About Python basis

@ TOC on the basis of Python

Python basis

- Understanding the Python
- Notes on
- the type of variable and
- input and output
- operator
- Data type conversion

About the Author

- This is my first blog, blog aims to record their experiences in the program on the road, I hope these experiences can have an impact on others, perhaps this knowledge stereotyped, but the perception of their own is the most precious.
- The following are learning insights and understanding of knowledge in Python
- on the basis of object-oriented Python basic syntax and Python, I'll be another fuss

Using Python

-Python core compiler is implemented by the c language
-Python of highly scalable, multiple levels of scalability
-Python and its standard library and powerful. These are the contribution of the whole community. Python developers from different fields, different areas of the advantages they will bring Python.
-Python advocating beautiful, clear and simple, is an excellent and widely used language
-Python belong interpreted language, so the disadvantage is slow efficiency, but also is made up of the performance of powerful computers
- more knowledge comes from learning courseware
-Python points as Python2 and Python3 version, the following are implemented in the Python3 basis
- life is short, I used Python

About Notes

- a complete program tend to have a lot of lines of code, people need to complete together, so the readability of the code (the code is neat and easy to read) requires very high, but also in everyday learning, will make a good comment when we review the program and, more clear thinking, and to facilitate changes and additions to the code
- comments are not executed in the program run
- comment division multiple-line comments and single-line comments
- a single number Notes:

#这是一个注释
print('注释为#号开头后面一行的内容')
#这也是一个注释

运行结果:
注释为#号开头后面一行的内容

- Multi-line comments

'''这是注释1
   这是注释2
   这是注释3
   ...
'''
print('在'''在三对引号中间的内容为注释内容'''可以换行')

'''这也是注释1
   这也是注释2
   这也是注释3
   ...
'''
运行结果:
在'''在三对引号中间的内容为注释内容'''可以换行

Variables and types

- variable will be appreciated that represents a mathematical letters, i.e., a = 1 b = 2 so that a + b = 3, similarly mathematics A represents a set of A, B that represents a collection B (Python is also set), then we can obtain the relationship between the set a, B, that is, in general, variable names represent some of the data we need, when we need to work with these data, we can use these names instead of data manipulation, convenient and save resources . Types of variables, to be understood as a mathematics may be a number, a may be an equation or a set of. Overall, the variables are used to store data in
a variable of type -Python:
Here Insert Picture Description
To see the type of data can be viewed by type (variable name)

-application:

a = 1
#这里让a就是变量名
b = 2
#这里b就是变量名
print(a+b)
a=3
#注意此时变量a被重新定义
print(a+b)

Run:
3
5

Identifiers and Key Words

- identifiers can be understood in conjunction with the above variables, such as variables in the introduction above, I let a = 1, then of course you can also b = 1 or safadfdf = 1, however, a wider range of identifiers, including the identifier variable name , the function name (method name), class name, summary, the identifier is defined by his name. Of course, there are identifiers in Python certain rules and methods:
- Rule:
identified by letters, underline, numbers, and numbers can not be used as the beginning, and the identifier is case sensitive.
Identifier last name known to do see Italy, easy and simple, for example, a student may be the first Student_1

- Keyword
Keyword is already using Python identifiers, for example, Print, the INPUT, BREAK
- see keyword
can enter help in the Python interactive mode ( 'keywords')
Here Insert Picture Description

Input and output

- Output
is simply a result of the program is running, for example:

#这是一个打印holle world 的程序
print('holle world')

The results (output):
Holle World

- is divided into a variety of output, above that for the normal output

  • Formatted output
    format of the output so that the output code easier and faster
#这是一个格式化输出的示例
a = 10
b = 2
c = '小明'
print('这里有%d个学生'%a)
#输出结果:这里有10个学生
print('这里有%d个学生,%d个老师'%(a,b))
#输出结果:这里有10给学生,2个老师 
print('我的名字是%s'%c)
#输出结果:我的名字是小明

Seen in the code% d,% s, Python is the operator,% behind different letters represent different types of data conversions
Here Insert Picture Description

  • Wrap output
    here requires a newline \ n newline i.e. data behind the newline is not in the same row of data
# \n 这就是换行符
print('我叫小明\n我今年18')
'''输出: 我叫小明
	   今年18 '''

- Input

Input is when we use the program, enter data into the program, for example, face recognition when we first entered our program face picture, when you open the phone, your fingerprint to unlock, enter the password is entered. In programming, the most common is the input data from the keyboard.

#一个输入程序
input_data = input('输入你的密码:')
print('你刚刚输入的密码是:%s'%input_data)
#这里运用了以上所有知识

run:
Here Insert Picture Description

Operators

There are several operators, you can contact the mathematical knowledge to understand

  1. Arithmetic operators
    to a = 5, b = 3 for example
    a - b results 2
    A + B results. 8
    A * B as result of 15
    A / B results 1.6666
    A // B 1 means the result of rounding
    a% b 2 results means more than taking
    a ** b result of 525 means a, b power
    over knowledge combined with mathematical knowledge enough to remember

  2. Assignment operator
    assignment operator is = partial
    name implies assignment operator is a value to a variable
    in Python

    #单个变量赋值
    a = 10 
    print(a)
    #结果为10
    
    #多给变量赋值
    b,c,d,e = 1,2,3,4
    print(b) #1
    print(c) #2
    print(d) #3
    print(e) #4
    
  3. Compound assignment operators
    compound assignment operators are established on the basis of the assignment operator

    #复合赋值运算符
    a = 10
    a += 1 #意为 a= a+1
    print(a)
    #此时 a =11
    

    To sum up:
    Here Insert Picture Descriptionthe above is easy to understand, to memorize multi-purpose

  4. Logical operators
    Logical operators currently is our common and (and) or (or) not (non)
    memorize the knowledge
    of high priority to the relational operators is low: not> and> or

    print(Ture and Fales) # Fales
    print(Ture and Ture)  # Ture
    print(Fales and Fales) # Fales 
    print(Ture or Fales) # Ture
    print(Ture or Ture)  # Ture
    print(Fales or Fales) # Fales 
    print(not Fales) # Ture
    print(not Ture)  # Fales
    
    

Data type conversion

Common data type conversions:
Here Insert Picture Description
different data in different situations, different types of needs, such as: a = 1 In this case a is an integer of course, a type may be a string, but if a = 'ha' , then the case can not be converted to a type integer.

a  =  10 
#此时a 是一个整数类型
print(type(a)) # int

a = str(a)
#此时a被强制转化为字符串
print(type(a)) # str

a = list(a)
#将a转化为一个列表,但是,此时a = [10]
print(type(a)) # list

a = int(a)
#此时a = [10] 是一个列表,不能直接转化为整数,所以程序报错

"Finish"

The above content is easy to understand, to memorize multi-purpose

Released two original articles · won praise 3 · Views 133

Guess you like

Origin blog.csdn.net/Abiezhu/article/details/103901501