py knowledge (updated daily) 6.5

1 integer int

Calculation and comparison

a.bit_length () # required number of decimal digits when converted to a binary occupied

2 Boolean value bool

True False True False

Digital converted into Boolean values: 0 False non 0 True

String into a Boolean value: empty string "" False True non-empty

Converted into a digital Boolean True = 1 False = 0

Boolean value into a string True = str (True) False = str (False)

3 strings

Role: store small amounts of data

Index (subscript): from left to right 0, 1, 2, 3 from right to left ;;;; -1, -2, -3, -4

(Out of range will complain when searching)

Slice: [Start position: is terminated] regardless of the end time is out of range to find the right care

Step: Find direction decision determines the look of the step size defaults to 1 by default direction from left to right

---- neuron progenitor list of strings are indexed [index]

The index is an accurate positioning element

Support indexing of support sections [index]

Slicing length may be out of range index length can not exceed the range [start position: is terminated: step]

Step: determine the direction to go, we decided to take the big steps

Commonly used methods

ALL CAPS upper

All lowercase lower

What to begin with startswith

To what end endswith

Go trailing spaces (default remove and remove line breaks) strip

The default split is separated by spaces, you can specify your own split

Replace replace ( "old" and "new")

Statistical statistics count the number of times a certain content appears

String formatting format () in three ways

is:

isdecimal () determines whether a decimal

isalnum judgment is not Chinese, letters, numbers

isalpha judgment is not Chinese, the letters

4for cycle

for i in xxx:

i variable for keywords in the keyword xxx iterable (can not use int or bool)

After the loop variable i points to the last element

Placeholders: pass or ...

5 range range

python3 print range is in itself

python2 is a list of print

range (the starting position, until the termination step) is connected to a comma

range (10) ---- range () terminates the start position 0 up to 10

Guess you like

Origin www.cnblogs.com/lyoko1996/p/10980931.html