Getting Started with Python basic knowledge necessary

An identifier of
the identifier is the name used for programming, for a variable, function, and the like named statement blocks, Python identifier letters, numbers, underscores not begin with a number, is case-sensitive.

An identifier have special meaning underscore, single underscore identifiers, such as: _xxx, indicates class property are not directly accessible, by class provides the interface required to access, can not be imported from xxx import *; at the beginning of double-underlined identifier, such as: __ xx, represents private members; identifier beginning and end of the double underline, such as: __ xx__, represents in Python built identification, such as: __ init __ () represents a class constructor.

2 Keyword

The above table is the Python keywords (reserved words), we can not use the keyword in a custom identifier.

3 quotes

Python can use quotation marks ( '), double quotation mark ( "), three marks ( ''' or  """) to represent strings, the start and end marks to be the same type, three marks may be composed of lines. As follows:

= ID ' 001 ' 

name = " John Doe " 

skill = '' ' 
singing and 
dancing ' '' 

skill = "" " 
Singing 
Dancing " ""

4 encoding
Python2 the default encoding is ASCII, if the content is Chinese character encoding can not be correctly read and output is not specified, for example, we want to specify the encoding is UTF-8, Python by adding # at the beginning - * - coding: UTF -8-- * - specified.

Python3 default encoded as UTF-8, so the use Python3, we usually need to specify the encoding.

5 O
Python using the output print (), the contents can be added in parentheses. As follows:

print('Hello Python')

Python provides an input (), allows the user to enter a string and place them into a variable. As follows:

name = input()
print('Hi',name)

Indent 6

Python is not used  {} to control classes, functions, logical judgment, but the indentation, the indentation variable spaces. As follows:

if True:
    print(True)
else:
    print(False)

More than seven lines

Python in general to identify the new line as the end of the statement, you can use  \ a single statement into multiple lines. As follows:

a = 128
b = 1024
c = 512
d = a + \
    b - \
    c

If included in  [], {}, () parentheses, is not needed  \. As follows

8 comments

Python used in single-line comments  #, multiline comments using three single quotes ( ''') or three double quotation marks ( """). As follows 

# I am a single line comment 

'' ' 
I am a multi-line comment 
I have is a multi-line comment 
' '' 

'' ' 
I am a multi-line comment 
I have is a multi-line comment 
. "" "

9 Data Types

  • Integer: may be of any size, including negatives

  • Float: that the decimal

  • String: single quote  ', double quotes ", three marks  ''' or  """enclosed text

  • Boolean: only  True, False two kinds of value

  • Null: The  None representation

  • Variables: variable

  • Constant: Immutable

Operators commonly 10.1

 

 

10.2 operator precedence

 

Welcome to the end of the text of public concern number, python community camp

Guess you like

Origin www.cnblogs.com/pypypy/p/12146940.html