"Ebola" Python day3

Source: Internet
Author: User

Look back on yesterday's question

1, the user input 3 times, and realize the number of times to show the remaining

1i =02  whileI < 3:3Username = input ('Please enter user name:')4Password = input ('Please enter your password:')5     ifUsername = ='YH'  andPassword = ='mm':6         Print(Login successful)7     Else:8A = 2-I9         Print('Password re-entered incorrectly')Ten         Print('You also have the%s chance remaining'%(a)) Onei + = 1
User Login

2, Calculate 1-2+3-4+5-6 ... 99, and so on, remove the value of 88

1 #first write how to implement the complete plus and minus chain, according to the analysis can be obtained odd is plus even minus2sum = 13Count =04 #If you want to get 99, you have to set the relative conditions.5  whileCount < 100:6 #Use the IF condition to separate odd, even7     ifCount = = 88:8Count + = 19         ContinueTen     ifcount%2 = =0: OneSum-=Count A     Else: -Sum + =Count -Count + = 1 the Print(sum)
View Code

int type

int is commonly used to convert other forms into numbers, and other forms of attention must be digital

The int contains the common 1,2,3,4,5 +-*%////

Common forms are converted from characters to numbers

Str converted toint Data Conversion

Boolean type (BOOL)

1. The bool type has only two forms of False ture

2, False is 0 ture is 1

convert bool type to int

Yes, if 0 is false, not 0 is ture.

1 i = 42 b = bool (i)3print(i)45 >>> 1
bool Value Conversion

STR converted to BOOL type

s = "" False

s = ' 0 ' Ture

Non-null characters are ture

String str

Index and slice of a string

1, in Python is starting with 0 as the first bit

Gu Tou Regardless of the end of the slicing method

 1  a = ' abcdefghigklmn '  2  print  (A[0:3]) #  Span style= "COLOR: #008000" > Prints the No. 0 to the second bit abc,0 can not write  3  print  (a[:]) #   print out as ABCDEFGHIGKLMN  4  print  (a[1:-3]) #  bcdefghigk  5  Span style= "COLOR: #0000ff" >print  (a[5:1]) #   reverse intercept FEDCB  6  print  (A[-1:1:2]) #   reverse intercept with a step of 2 nlghfd  
View Code

Common ways of string editing

1A ='gaojian12*'2A1 = A.capitalise ()#Initial capital Letter gaojian12*3A2 = A.upper ()#All caps gaojian12*4A3 = A.lower ()#All lowercase gaojian12*5 " "6 about all uppercase all lowercase issues are often applied to system assurance case- insensitive7 s_str = ' acEQ3 '8 you_input = input ("Please enter a verification code, not case sensitive")9 if s_str.upper () = = You_input.upper ():Ten print (' input succeeded ') One Else: A print (' Please re-enter ') - " " -a4 = a.swapcase ()#Case Flip theAA ='Gao Jian Tao' -A5 = aa.title ()#the first letter of each word is capitalized, the difference is the space Gao Jian Tao -A6 = A.center (20,'@')#Length 20 fills both sides with @, and center @ can also be a space @@@@@[email protected]@@@@ -A7 = A.count ('a', 0,9)#The number of occurrences of an element in a string, the number of times a slice query a appears print (A7) <<< 2 +Aa1 ="wwho\t" -A8 = Aa1.expandtabs ()#put \ t before the completion of a tab 8 key print (A8) ' wwho ' If the preceding characters are more than 8 to 16 characters +A9 = A.startswith ('Ian', 4,7)#returns a Boolean value in 第4-7位 to determine whether the print (A9) begins with Ian Ture AA10 = A.endswith ('Ian', 4,7)#returns a Boolean value for print (A10) at 第4-7位 to determine whether to end with Ian Ture atA11 = A.find ('Ian'1,6)#in 1,6 to find whether the element in the string exists, if it can find the return position, cannot find return-1 print (A11) returns 4 -A12 = A.index ('Ian', 1,6)#An error has been found in the presence of the element 1,6 for the search string -A13 = A.split ('a')Print(A13)#[' G ', ' Oji ', ' n12* '] in what division, and eventually form a list this list does not contain this split element.  - #ret91 = ' title,tilte,atre, '. Rsplit (' t ', 1) starts from the right to the first T, and does not contain a list of T-splits - #print (ret91) [' Title,tilte,a ', ' re, '] -Name='*egon**' in Print(Name.strip ('*'))#Delete the * number on both sides can also be replaced with spaces, letters and other things - Print(Name.lstrip ('*'))#Delete the * number on the left to Print(Name.rstrip ('*'))#Delete the * number on the right + #format three gameplay formats output -res='{} {} {}'. Format ('Egon', 18,'male') theres='{1} {0} {1}'. Format ('Egon', 18,'male') *res='{name} {age} {sex}'. Format (sex='male', name='Egon', age=18) $ #ReplacePanax NotoginsengName='Gao Say:i has one tesla,my name is Gao' - Print(Name.replace ('Gao','Gaojiantao', 1))#replace the old ' Gao ' for Gaojiantao replacement number 1 the #Gaojiantao Say:i has one tesla,my name is Gao + ##is系列 AName ='gaojiantaoshuai123' the Print(Name.isalnum ())#The string is made up of letters or numbers, and the returned value is Tuer + Print(Name.isalpha ())#The string consists only of letters False - Print(Name.isdigit ())#string only consists of numbers False
View Code

Tuple Tupe

1. Cannot be changed or modified or sliced

2, Ganso with (4, ' Huju ', (' Ju ', ' yh ')) said

Lists List

1. Use [] to express

Dictionary

1, with the key to the expression

For syntax

1  forIinchRange (1,10):2     Print(i)3 4  forIinchRange (1,10,2):#Step Size5     Print(i)6 7  forIinchRange (10,1,-2):#Reverse Step8     Print(i)
View Code

"Ebola" Python day3

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.