First, the introduction of Python
1. First Python program
Enter print (' Hello,world ')
2. File header
#!/usr/bin/env python
# -*- coding: utf-8 -*-
3. Comment Line Comment: #注释内容 more comments: "' note content ' ' 4. If you import other. py files when you execute Python code for the PYc file, a. pyc file with the same name will be generated automatically during execution, and the file is compiled by the Python interpreter. Bytes generated after the code. Second, the variable 1. Why variable variables are used to record the state of a program's Operation 2. Declaration and reference of a variable name= ' Sam ' #变量的声明 print (name) #引用并且打印变量名name对应的值 3. Variable name range variables can only be letters, numbers, or underscores The first character of any combination variable name cannot be a number the following keywords cannot be declared as variable names: [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' Raise ', ' return ', ' try ', ' while ', ' with ', ' yield '] three, only one input output ython3 input, and python2 in the same way as the Raw_input, is the user's input as a string , Python2 also has the command of input, which is what type the user enters, and what type () is saved to see the data type
# !/usr/bin/env python name=input (' Please enter user name:')print(name)
Perform
c:\users\administrator>python D:\python_test\hello.py Please enter your username: Samsam
When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely:
# !/usr/bin/env python Import Getpasspassword=getpass.getpass (' Please enter password:')print(password)
Perform
c:\users\administrator>python D:\python_test\hello.py Please enter your password:123456
Iv. Simple Operators
Arithmetic operator: +,-,*,/,%,**,//
Note: The division in Python is a floating-point operation, and/or can be divisible
* * is a power operation, such as 7**2 's operation result is 49
Assignment operator: =,+=,-=,*=,/=,%=,**=,//=
Comparison operator: ==,!=,<>,<,>,<=,>=
Bitwise operator:$,|,^,~,<<,>>
Logical operators: And,or,not
First knowledge of Python