First, the object may be acquired approximately equal to the iterative cycle fo
Two, int \ str \ bool data types included in each of the corresponding method, collectively, for the data type of the class or method, according to the data type of the corresponding object created for the object
Third, the use underline converting each element in the list for the string
test=["English","is","good"] v="_".join(["English","is","good"]) print(v) 输出结果 English_is_good
Four, range of differences in python2 and python3
python2:
range: create immediate use, into memory
xrange = python3 of Range, when for one cycle to create, save memory
python3:
range: the time for one cycle to create, save memory
Example:
for A1 in Range (0,100,2): # of from about equal to 0 and less than 100, in steps of small to large intervals of the input digital straight sets 2 2 Print (A1) for A2 in Range (100,0, -2): # of from about equal to 0 and less than 100, step 2 of the descending interval of the input digital straight sets 2 Print (A2)
Fifth, to achieve a integer addition Calculator
String input = "5 + 9"
test="5+9" v1,v2=test.split("+") a=int(v1) b=int(v2) c=a+b print(c) 结果:14
Sixth, the content entered by the user computing has several decimal digits and a few words
= C1 0 C2 = 0 InP = INPUT ( " Enter your name: " ) for Item in InP: IF (item.isdecimal ()): C1 = C1 +. 1 the else : C2 = C2 +. 1 Print (C1, C2) Results : 314
Seven, waiting for the user to enter the name, location and preferences, according to the user's name and preferences, arbitrary reality
v="name:{0},addre:{1},kk:{2}" name=input("<<<") addre=input("<<<") kk = input("<<<") v1=v.format(name,addre,kk) print(v1) 结果: name:nihao,addre:北京市,kk:加油
Eight: circulation prompts the user to enter a user: user name, password, email (required the user to enter up to 20 characters, if more than only the first 20 characters are valid). If the user inputs q or Q represents no further input, the user input in tabular form printed
s="" while True: v1=input("用户名:") if v1=="q" or v1=="Q": break v2=input("密码:") if v2=="q" or v2=="Q": break v3=input("邮箱:") if v3=="q" or v3=="Q": break template="{0}\t{1}\t{2}\n" v=template.format(v1,v2,v3) s=s+v print(s.expandtabs(20))