1.for Cycle
The user iterates through the contents of an object in order.
1 li = [11,22,33,44]2 for in Li:3 print i
else for Loop
This feature is currently only found in the For loop.
The specific condition is that when the program inside the For loop body executes correctly, it executes the code below the else.
2.enumerate
Adds an ordinal to an object that can be iterated.
Enumerate (sequence string [, start ordinal])
1 li = [11,22,33]2 for in enumerate (Li, 2):3 Print(k,v)
Python basic data type 1. String
Use a pair of ' \ ' \ ' \ ' ' cause the content. Python thinks it's a string. That is, the STR type
The common methods of strings are:
1Str.capitalize#Capitalize first letter2Str.center#Center Display3Str.count#Count The number of occurrences of a string4Str.endswith#whether to end with a string5Str.expandtabs#the TAB key is converted to a space. Default to 8 spaces6Str.find#look for the position of the sequence. Wood has found back-17Str.index#look for the position of the sequence. When the wood is found, the error8Str.format#formatted output9Str.isalnum#determines whether a string is a number or a letterTenStr.isalpha#determine if the strings are all letters OneStr.isdigit#determine if a string is a number AStr.isspace#determines whether a string is a space or a TAB key -Str.islower#determines whether a string is all lowercase -Str.isupper#determine if a string is all uppercase theStr.istitle#determines whether a string starts with a capitalization -Str.join#Connection -Str.ljust#content is left-aligned. The right padding. -Str.rjust#the content is right-justified. Left padding. +Str.lower#Convert a string to lowercase -Str.upper#Convert a string to uppercase +Str.strip#cut off the spaces at both ends of the string AStr.lstrip#cut off the space to the left of the string atStr.rstrip#cut off the space to the right of the string -Srt.replace#Replace -Str.split#Split -Str.startswith#whether to start with a string -Str.swapcase#uppercase and lowercase in a string
2. List
A list is the most commonly used Python data type and can appear as a comma-separated value within a square bracket.
Create a list:
1 name_list = ["a""b""C" ]2 or 3 name_list = list (["Tom" " Tony " " Jerry "])
Common ways to List are:
1Li.append#adding elements2Li.remove#Delete an element3Li.pop#randomly deletes an element. and print. The last one is usually deleted .4Li.count#number of occurrences of statistical elements5Li.extend#two lists merged into one6Li.index#find the subscript of an element7Li.insert#Insert an element into the list8Li.reverse#reverse Order9Li.sort#Sort
3. Digital
int (integral type)
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~92233720368547758074. Boolean value TRUE or False1 or 05. Tuples
Tuples are similar to lists. But with () to represent
Cannot be modified after a tuple's element definition
To create a tuple
1 name = ('Tony'Alex'Tomy' )2or3 name = tuple ('Tony' 'Alex'Tomy')
Python Learning notes (2)