#基本数据类型:
#int
# i=100
#print (I.bit_length ())
#十进制转化成二进制的有效位数
#数字类型转化成字符串类型
" "
int<--->str
STR--->int int (str) Condition: The string must consist entirely of numbers.
int--->str str (int)
" "
# Age=int (Input (' >>> '))
# Print (Age,type (age))
# S1=STR (123)
# s2=123
# Print (S1,type (S1))
# Print (S2,type (S2))
"""
bool<--->int True---> 1 False---->0
int---->bool Nonzero is true, 0 False
"""
# Print (int (True))
# Print (int (False))
# Print (bool (+))
# Print (bool ( -1))
# print (bool (0))
"""
BOOL--->str str (True) str (False)
STR--->bool non-null is true ' empty string--->false
"""
# s1= '
# if S1:
# Print (666)
#str String
#索引, Slice, step
# s= ' python12 period '
# S1=s[0]
# Print (S1,type (S1))
# S2=s[4]
# Print (S2)
# S3=s[2]
# Print (S3)
# S4=s[-1]
# Print (S4)
# S6=s[0:6] #切片: Gu Tou Disregard Butt
# S6=s[:6] #切片: Gu Tou Disregard Butt
# Print (S6)
# S7=s[1:4]
# Print (S7)
# s8=s[1:]
# Print (S8)
# s9=s[:]
# Print (S9)
# S10=s[:5:2]
# Print (S10)
# S11=s[4::2]
# Print (S11)
# S12=s[-1:-5:-1]
# Print (s12)
# S13=s[-3:-1]
# Print (S13)
#字符串的常用操作方法
#s = ' Laonanhai '
#**capitalize First letter uppercase, other lowercase letters
# s1=s.capitalize ()
# Print (S1)
#* Center Center
# S2=s.center ("*")
# Print (S2)
#*** Upper: All caps
# lower: all lowercase
# s3=s.upper ()
# s31=s.lower ()
# Print (S3)
# Print (S31)
" "
Example:
code= ' Qadr '. Upper ()
your_code=input (' Please enter a verification code, not case sensitive: '). Upper ()
if Your_code==code:
print (' Verification successful ')
" "
#*** startswith: Judging by what content begins,
#返回bool, slices can be sliced and slices are separated by commas.
#***endswith
# S4=s.startswith (' l ')
# S41=s.startswith (' Lao ')
# s42=s.startswith (' n,3,6 ')
# Print (S42)
# Print (S4)
# Print (S41)
# #*swapcase Case Flip
# s5=s.swapcase ()
# Print (S5)
#*title () capitalize the first letter of each word that is not separated by a letter.
# ss= ' gdsj Wusir6taibai*ritian '
# s6=ss.title ()
# Print (S6)
#*** Index by Element
#index: Indexed by element, can be sliced, error not found
#find: Indexed by element, can be sliced, cannot find return-1
# s7=s.find (' a ')
# Print (S7)
#s71 =s.find (' A ', 2,)
# s71=s.find (' Q ',)
#print (S71)
# s72=s.index (' Q ',) #找不到报错
# Print (S72)
# Print (S71)
# ss= ' \talex\n '
# Print (ss)
#*** Strip remove spaces, newline characters, tab characters from front and back.
# S8=ss.strip ()
# Print (S8)
# ss= ' Ablabsexsba '
# S9=ss.strip (' a ')
# S10=ss.strip (' abs ')
# S11=ss.lstrip (' x ')
# S12=ss.rstrip (' K ')
# Print (s12)
" "
username=input (' Please enter user name '). Strip ()
if username = = ' Bowl rong ':
print (' login successful ')
" "
#***split str--->list
#默认以空格分割
s= ' wusir Alex Taibai '
st= ' Wusir,alex,taibai '
st1= ' Qwusirqalexqtaibai '
S10=st.split ()
print (S10)
# s101=st1.split (', ')
s102=st1.split (' Q ', 2)
print (s102)
#***join
#在某些情况下, List---str
s= ' Alex '
s11= ' + '. Join (s)
print (S11)
l=[' Wusir ', ' Alex ', ' Taibai '
s111= ". Join (L)
Print (S111,type (s111))
#repalce
s= ' small pink GHLASDFG small pink
s13=s.replace (' Little pink ', ' big Hammer ')
s12=s.replace (' Little pink ', ' big Hammer ', 2)
print (S13)
print (S12)
s= ' Fdsajlskgjdsaf '
#公共方法:
Total number of #len ()
print (len (s))
#count calculates the number of occurrences of some elements, which can be sliced
C1=s.count (' F ')
Print (c1)
#格式化输出,
#三种方法:
# msg= ' My Name {}, this year {}, hobby {} '. Format (' Taibai ', ' ' ", ' Girl ')
# Print (msg)
# msg= ' My name {0}, this year {1}, hobby {2}, I still call {0} '. Format (' Taibai ', ' "', ' Girl ')
# Print (msg)
msg= ' My name {name}, this year {age}, hobby {hobby}, '.
format (name= ' Taibai ', hobby= ' girl ', age= ')
Print (msg)
name= ' jinxin123 '
print (Name.isalnum ()) #字符串由字母或数字组成
print (Name.isalnum ()) #字符串只由字母组成
print (Name.isdigit ()) #字符串只由数字组成
s= ' Fdsagdsfgfdsadsaf '
# s= ' Alex '
# Print (s[100])
print (s[0])
print (s[1])
For I in S:
print (i+ ' SB ')
#for variable in to iterate over an object:
# Pass
Python---Underlying data type