Python Foundation Day4

Source: Internet
Author: User
Tags true true

Overall outline
One
1,int. Number: operation. 1, 2,3 ...
2,bool. true: false.
3,str. Simple and small amount of storage data, and the corresponding operation name = ' Alex ',
4,tupe. (1, ' Alex ')

5,list: Large amount of data, [1, ' ses ', true,[1,2,3],{' name ': ' Jinxin '}]
6,dict: Dictionary {' name ': ' Jinxin ', ' age ':, ' name_list ': [' Zhang San ', ' John Doe ']}

1, about the conversion of bool and STR
bool: True True 1, false false 0

1 String--->bool value bool (str)

non-empty string converted to bool True
' empty string converted to bool False '
Example
s = ' Sdfa '
S1 = ' a '
s2 = ' 1 '
s3 = ' '
Print (bool (s))
Print (bool (S1))
print (bool (s2))
Print (bool (S3))

#bool--->str value

Cases
A = str (true) # ' true '
A1 = str (2 > 1) # ' True '
Print (A1,type (A1)) ' True '

b = str (false) # ' false '

Print (A,type (a))
Print (B,type (b))


Because the null is False
Name = ' '
If Name:
Print (' input correct ')
Else
Print (' Please enter content ')

2. Index and slice [start position: End Position: Step]
Example

1, index and slice [start position: End Position: Step]
S1 = ' python full stack phase 8 '
Index starting from 0 [index (subscript, index)]
# print (s1[0]) p
# print (s1[3]) h
# print (s1[5]) n
# print (s1[6]) full
# print (S1[-1]) period

#切片 Gu Tou Disregard butt Note 1 6th no actual to 5th 2 would have 9 characters but 10 12 19 end up so default to the last 3
# print (S1[0:6])
# print (S1[6:10])

Full Stack 8 issue


#pto
Take the piece
[Start Position: End Position: Step]

#s1 = ' python full stack 8 '
# print (S1[0:5:2])
# print (S1[0:7:3]) ph full

#倒取值: Add step 3::1 and 3::-1 difference 3::1 print hon full stack phase 8 3::-1

# print (S1[3::-1])

# print (S1) #不变
# s2 = S1[0:6]
# Print (S2)
Python


3 String about uppercase lowercase
ret = ' Alexs '
#字符串的使用方法.
#1 Capitalize first letter, other all lowercase str1
Print (STR,STR1) fixed usage
ret = "Wangyan"
Ret1 = "Wangyan". Capitalize ()
Print (RET,RET1)
C
Example all uppercase or full lowercase
ret = ' Wangyan '
Ret2 = Ret.upper ()
Ret3 = Ret.lower ()
Print (RET2,RET3)


Code = ' A '
Your_code = input (' Enter verification code, case insensitive ')
if Your_code = = ' a ' or your_code = = ' A ':
Print (' you entered the correct ')
Else:print (' Please re-enter ')

Case-insensitive usage
Code = ' Wangyan '. Lower ()
Your_code = input (' Enter a case-insensitive letter '). Lower ()
if code = = Your_code:
Print (' correct it ')
else:
Print (' re-enter ')

Code = ' Adee '. Upper ()
Your_code = input (' Please enter a verification code, not case sensitive '). Upper ()
if Your_code = = Code:
Print (' you entered the correct ')
Else:print (' Please re-enter ')
‘‘‘
# case Flip . Swapcase ()
Example
Code = ' Wangyan '
Code1 = Code.swapcase ()
Print (CODE,CODE1)
Wangyan Wangyan

#以特殊符号或者空格隔开, the first letter of each string is capitalized title ()
Example
Code = ' Wangyan '
Print (Code.title ())
Wangyan
  Fixed format      string. Center (number is the space between the center of the string and the ' fill content ')
Code = ' Wangyan '
Print (Code.center, ' @ ' ) @@@@@@@@@@@@@[email protected]@@@@@@@@@@@@

# * returns BOOL value StartsWith endswith

Code = ' Wangyan '
Code1 = Code.startswith (' W ')

True as long as the first one or a few are false otherwise
ret = ' 123454 '
Ret2 = Ret.endswith (' 3 ', 0, 3)
Print (Ret2)

ret = "Alex"
# Ret5 = Ret.startswith (' l ', 1,3) # Slice
# Print (RET5)
True
# Ret6 = Ret.endswith (' S ',-2,)
# Print (RET6)
False

# * * Number of Count letters
Example
ret = ' Wangyanluodan '

Ret6 = Ret.count (' A ', 0,6)
Print (RET6)
2 x
ret = Alex
# ret7 = Ret22.count (' a ')
# ret7 = Ret22.count (' ale ') # whole vs. individual
# ret7 = Ret22.count (' W ') # 0
# ret7 = Ret22.count (' A ', 0,7) # Slice of Count
# Print (RET7)

TAB key Completion
# a2 = "Qwaaaaaaaa\taa"
#\ t in front of the completion
# By default, a tab key becomes 4 spaces, if the character in front of the tab is less than 8, then complete 8, if the character in front of the TAB key is more than 8 less than 16, then complete 16, and so on each complement of 8 .
# ret8 = A2.expandtabs ()
# Print (Ret8,len (RET8))
Example
a1= "Qwaaaaaaaa\taa"
A2 = A1.expandtabs ()
Print (A2)
Find and Index lookups
ret = ' Aleaxs '
# * Find Index by element (find first element), cannot find return-1
# ret9 = Ret.find (' a ')
# # RET9 = Ret.find (' W ', 0,5)
# Print (RET9)
#index and find use the same, the element can not be found, will be error
# ret10 = Ret.index (' W ')
# Print (ret10)


a1= "Qwaaaaaaaa\taa"

A2 = A1.find (' B ')
Print (A2) -1
‘‘‘
a1= "Qwaaaaaaaa\taa"

A2 = A1.find (' a ')
Print (A2) 2

a1= "Qwaaaaaaaa\taa"

A2 = A1.index (' a ')
Print (A2) 2
a1= "Qwaaaaaaaa\taa"

A2 = A1.index (' W ')
Print (A2) error

#* Strip Remove the space before and after the string and the element you want to remove

Ret
# ret11 = ' Alex '. Strip ()
# Print (ret11)
‘‘‘
name = ' Alex '
Username = input (' Please enter your user name: '). Strip ()
If username = = Name:
Print (' Login successful ')
‘‘‘
# ret11 = ' Alex '. Lstrip ()
# Print (ret11)
# ret11 = ' Alex '. Rstrip ()
# Print (ret11)
#一:
# ret12 = ' Asldfkjafa '. Strip (' a ')
# Print (ret12)
#二:
# ret13 = ' Asldfkjafa '. Strip (' sa ')
# Print (ret13)
# ret13 = ' Asldfkjafa '. Strip (' Salf ')
# Print (ret13)
# ret14 = ' Asldfkajafa '. Strip (' Sawlf ')
# Print (ret14)

#split * Splitting a string into a list
# ret15 = ' jinxin Alex Wusir '
# ret16 = Ret15.split ()
# Print (ret16)
# ret15 = ' Jinxin,alex,wusir '
# ret16 = Ret15.split (', ')
# Print (ret16)
# ret15 = ' title Tle tlie '
# ret16 = ret15.split (' t ')
# Print (ret16)
# * Replaces replace
# ret18 = ' Pink turned on pink-grade third pink '
# ret19 = ret18.replace (' Pink ', ' Tender Green ', 1)
# Print (ret19)

# Formatted output format
#第一种:
# ret20 = ' name:{},sex:{}, Height: {} '. Format (' Alex ', ' Ladyboy ', 178)
# Print (ret20)
#第二种:
# ret20 = ' Name:{0},sex:{1}, Height: {2},name:{0} '. Format (' Alex ', ' Ladyboy ', 178)
# Print (ret20)
#第三种: Key-value pairs
# ret20 = ' Name:{name},sex:{sex}, Height: {high},name:{name} ' \
#. Format (sex = ' ladyboy ', high = 178,name= ' Alex ')
# Print (ret20)

# Judging conditions
# name= ' 123 '
# Print (Name.isalnum ()) #字符串由字母或数字组成
# Print (Name.isalpha ()) #字符串只由字母组成
# Print (Name.isdigit ()) #字符串只由数字组成


s = ' AELSDSKJL '
# s = s[1:]
# print (s)

# print (len (s)) #测量长度
# index = 0
# while True:
# print (S[index])
# index + = 1
# if Index = = Len (s): Break
#for variable in to iterate over an object
# for I in S:
# Print (i)
s = ' FS4DKJLA123FKJ2DSA '
Count = 0

For I in S:
If I.isdigit ():
Count + = 1
Else:print (666)
Print (count)







Python Foundation Day4

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.