3, the basic data types

A basic data types .python
1. int ==> integer. Use main math for trekking into ⾏
2. str ==> terminated string, a small amount of data can be stored and Fixing trekking operation corresponding
3. bool = => true and false judgments, True, False
4. List ==> zoomed large amount of data storage. using a [] are shown in table monitor
5. tuple => tuple, can not change the raw using a hair ⽣ () shown in table PLAY
6 . dict ==> dictionary, save key-value pairs, ⼀ the same amount of data you can save a lot zoomed
7. set ==> set zoomed save a lot of data volume. can not be repeated. in fact does not save the value of dict

Two integer (int)
in python3 are all integer int. Python2 but if the amount of data comparison zoomed large. Prints using a long type.
Long type does not exist in the python3

Trekking can perform while the integer operation:
BIT_LENGTH () calculates the integer representing a binary code Use ⼆ used in memory length.

Three Boolean value (bool)
value only True, False bool value is not operating.
Conversion issues:
str => int int (str)
int => str str (int)
int => BOOL BOOL (int) 0 is False. is non-0 True
bool => int int (bool) True is 1, False is 0
STR => bool bool (STR) is the empty string False, not empty is True
bool => STR STR (bool) bool value is converted to the corresponding to "value"

IV. Terminated string (str)
to connect to a character string. Use in python with ',', '', '' 'due to the content of the character string is called a string.

4.1 slices and index
1. The index The index is a subscript. Remember, the subscript starts at 0

S1 = " Pthon cattle B " 
Print (S1 [0])
 Print (S1 [. 1 ])
 Print (S1 [2 ])
 Print (S1 [. 3 ])
 Print (S1 [. 4 ])
 Print (S1 [. 5 ])
 Print (S1 [. 6 ])
 Print (S1 [. 7 ])
 # Print (S1 [8]) # 8 not being given bounds 
Print (S1 [-1 ])
 Print (S1 [-2])

2. slice, we can use the index used to intercept the content portion terminated string
Syntax: STR [start: end]
Rule: care regardless of the end, from the start to the end start position taken taken but not including end

= S2 " Python cattle B " 
Print (S2 [0:. 3])      # 0 does not contain the acquired 3. 3. Results: PYT 
Print (S2 [. 6:. 8])      # results most ⽜ bovine 
Print (S2 [ 6: 9])      # is largest Great care is 8. However, according to the head regardless of Ding not want to have to take 8 to 9 
Print (S2 [6:10])     # If the right side has been a relatively a large value is largest. obtained in the last 
Print (S2 [. 4:])       # . to obtain the final value of a last frame that may not be not give. 
Print (S2 [-1: -5])    # Gets this is from -1 to -5 .. do not get any results from the value -1 how right you also count the number of not less than -5 
Print (s2 [-5: -1])    # result on the cattle, care regardless of the end 
Print (s2 [ -5:])      # nothing to write is not the last of the 
print(S2 [: -. 1])      # accessible to a penultimate 
Print (S2 [:])        # is output
Leaping interception
print (s2 [1: 5: 2]) # from the first frame beginning to take, get to the fifth, every 2 to take a result: yh, Analysis:. 1:. 5 => ytho => YH 
Print (S2 [: 5: 2]) # scratch every two to take a fifth.
Print (S2 [4 :: 2]) # 4 from the start to the end of each take a take two.
Print (S2 [-5: : 2]) # from -5 to take each of the last two take a ⼀.
Print (S2 [-1: -5]) # -1: What -5 because nothing is taken from left to right..
Print (s2 [-1: -5: -1 ]) # ⻓ step length is -1 time on the value of the right to left.
Print (S2 [-5 :: -. 3]) from the penultimate # 5 start to the beginning, did not take a three, the results oy

Step ⻓: If is an integer, taken from left to right then from right to left with a negative value is set to a default 1...
Slice syntax:
STR [Start: end: STEP]
Start: start position
end: end position
STEP: step ⻓

Related operating methods ⽅ 4.2 strings
strings are immutable objects, any operation on the original string is a string not have any influence

1. capitalization Huzhuan

# The first letter capitalized string, other variations lowercase letters 
S3 = ' My IS Fangxing the Name ' 
s3.capitalize () 
Print (S3)        # output does not find any changes. Because individual cases from the character ri string itself is not born not made ⽣ change. we need to re-acquire 
s4 = s3.capitalize ()
 Print (s4)
All to lower case # 
S3 = 'My IS Fangxing the Name'
Print (s3.lower ())
# Transfer all uppercase 
S3 = 'My IS Fangxing the Name'
Print (s3.upper ())
# Application, the user input START Using the check authentication code is legitimate 
verify_code = "ABDE"
user_verify_code = INPUT ( "Please enter this code:")
IF user_verify_code.lower () == verify_code:
Print ( "authentication successful")
the else :
Print ( "verification failed")
Case # mutual conversion 
S3 = 'My IS Fangxing the Name'
Print (s3.swapcase ())

# Infrequently Using 
S3 = 'My Fangxing the Name IS'
s4 = s3.casefold () # ⼩ converted to lowercase, and the difference between the lower of:. Lower () to support some characters ⽀ not good enough
# casefold () for all words ⺟ mother valid. ⽐ some words, such as Eastern Europe ⼀ ⺟ mother
Print (S4)
S2 = "БBß" # Russia, the United States and Germany
Print (S2)
Print (s2.lower ())
Print (s2.casefold ())

Each word ⺟ mother separated by a special character first word ⺟ therefore especially female zoomed capital
s3 = "alex eggon, taibai * yinwang_ Twisted Vine"
RET = s3.title () # Alex Eggon, Taibai * Yinwang_ twist vine
print ( RET)
# in text files can be considered a special character
s4 = "alex ⽼ appearing boy wusir" # Alex ⽼ old old boy Wusir
Print (s4.title ())

2. cut to cut

Guess you like

Origin www.cnblogs.com/fxxy/p/10931959.html