Learning Content:
1. Integrated Development Environment:
The classic text editor under VIM and Emacs#linux
Eclipse #Java IDE, Multiple languages supported
Visual Studio #微软开发的IDE, Multiple languages supported
notepad++,sublime, etc.
Pycharm is primarily used in the IDE for Python development
2. Formatted output mode
Placeholder%s: string,%d: integer,%f: floating-point number
Example:
Name = input ("name:"= input ("age:"= input ( " Salary: " "-------------mes of%s------------Name =%sage =%ssalary =%s from retired time =% s--------------end----------------" % (name,name,age,salary,65-age )Print (msg)
View Code
Function: make the output more flexible
3. Data operation
Integer: Integral type
Plural
Floating-point number: numbers with decimals
Boolean value: only two states: true (true) and False (false)
String
4. Circulation
For Loop:
Example:
for in range (0,100,4): #0: start bit, 100: cut-off, 4: step if i% 2 = = 0: Print("loop:", I) for in range (1,101,2 ): print("loop:", I)
View Code
While loop
Example:
user ="a"passwd="b"C=0 whileC < 3: Username= Input (">>:") Password= Input (">>:") ifuser = = Username andpasswd = =password:Print("wlecome%s to ..."%User) break Else: Print("user name or password is wrong, re-enter!") C+ = 1ifc = = 3: D= Input ("still want to play? y/n:") ifD = ="y": C=0Else: Print("Goodbye")View Code
You can add an else statement in a loop expression that represents a program that executes when the loop ends Normally.
5. Continue break
Continue means skipping this loop, which means ending the current loop
6. Flag Bit
Use a flag when you need to have a condition, or need a decision
7, Nested Loops
Used to implement multiple loop outputs, multi-layer selection menu.
8. List
An expression that uses the bracket flag to contain multiple contents, such as strings, integers, lists, tuples, dictionaries, and so On.
Cases:
A = ["name", 1,["Age","name" ]]Print(a)
View Code
List of queries
Check (slice)
A = [' I ', ' am ', ' siffre ', ' Thanks ']
Print (a)
Print (a[1:3]) #1, a third
Print (a[:3]) #开始, a third
Print (a[1:]) #1, and finally
Print (a[:]) #所有
Print (a[::2]) #步长
Print (a[1:-1]) #-1 represents the last, in turn -2,-3,-4
Print (a[1::-1]) #反向
Output:
[' I ', ' am ', ' siffre ', ' Thanks ']
[' am ', ' Siffre ']
[' I ', ' am ', ' siffre ']
[' am ', ' siffre ', ' Thanks ']
[' I ', ' am ', ' siffre ', ' Thanks ']
[' I ', ' Siffre ']
[' am ', ' Siffre ']
[' am ', ' I ']
Increment of List (add)
1) append, Add data to the last bit of the list
A = [' I ', ' am ', ' siffre ', ' Thanks ']
A.append (' you ') #在最后添加
Print (a)
Output:
[' I ', ' am ', ' siffre ', ' Thanks ', ' you ']
2) insert, Add data to the specified location in the list
A = [' I ', ' am ', ' siffre ', ' Thanks ']
A.insert (1, ' You ')
Print (a)
Output:
[' I ', ' You ', ' am ', ' siffre ', ' Thanks ']
Modification of the list
1) Modify by index
A = [' I ', ' am ', ' siffre ', ' Thanks ']
a[1] = ' Hello '
Print (a)
Output:
[' I ', ' Hello ', ' siffre ', ' Thanks ']
2) Modification by sectioning
A = [' I ', ' am ', ' siffre ', ' Thanks ']
a[1:2] = [' Hello ', ' World ']
Print (a)
Output:
[' I ', ' Hello ', ' world ', ' Siffre ', ' Thanks ']
Deletion of the list
1) remove deletes the specified content
A = [' I ', ' am ', ' siffre ', ' Thanks ']
A.remove (' I ') #指定切片也可以
Print (a)
Output:
[' am ', ' siffre ', ' Thanks ']
2) Pop Default Delete tail, You can also specify the index delete , after deletion will have a return value
A = [' I ', ' am ', ' siffre ', ' Thanks ']
A.pop ()
Print (a)
Output:
[' I ', ' am ', ' siffre ']
3) del Deletes the specified element by index, or it can delete the entire table
A = [' I ', ' am ', ' siffre ', ' Thanks ']
Del a[2]
Print (a)
Output:
[' I ', ' am ', ' Thanks ']
4) clear clears the contents of the list, preserves the list
A = ["name", 1,["age", "name"]]
A.clear ()
Print (a)
Output:
[]
9, List of functions
1) Count () Number of an element in the statistics list
A = [' i ', ' am ', ' siffre ', ' Thanks ', ' i ']
b = A.count (' I ')
Print (a)
Print (b)
Output:
[' i ', ' am ', ' siffre ', ' Thanks ', ' i ']
2
2) Extend () Add another list content to the current list , as Follows: b the list is Unchanged.
A = [' I ', ' am ', ' siffre ', ' Thanks ']
b = [1, 2, 3]
A.extend (b)
Print (a)
Output:
[' I ', ' am ', ' siffre ', ' Thanks ', 1, 2, 3]
3) index () queries the indexed value of an element
A = [' I ', ' am ', ' siffre ', ' Thanks ']
b = A.index (' am ')
Print (b)
Output:
1
4) reverse () Reverses the position of the elements in the list (the index changes)
A = [' I ', ' am ', ' siffre ', ' Thanks ']
A.reverse ()
Print (a)
Output:
[' Thanks ', ' siffre ', ' am ', ' I ']
5) sort () Sorts the elements in the list, the default ascending order, which can be reversed by sort (reverse=true), the numbers sorted by size, and the other characters by the ASC table corresponding values
A = [1, 5, 7, 33, 67, 2]
A.sort ()
Print (a)
Output:
[1, 2, 5, 7, 33, 67]
Determines whether the list contains the corresponding elements (in, count ())
A = [' I ', ' am ', ' siffre ', ' Thanks ']
If ' AM ' in a:
Print (' Yes ')
Else
Print (' No ')
Output:
Ok
A = [' I ', ' am ', ' siffre ', ' Thanks ']
b = A.count (' Hello ')
Print (b)
Output:
0 #表示没有
Identity judgment
A = [1, 5, 7, 33, 67, 2]
b = Type (a) is List
Print (b)
Output:
True
A preliminary study of Python