python based learning - Operator & basic data type

First, the operator

1 arithmetic operators: +, -, *, /, *, @,%

 

2 assignment operator

And arithmetic operators with the assignment operator is used, the result obtained is a clear value

Case 

count=count+1
count+=1

 

3 comparison operators:! <,>, =,> =, <=, ==

4 logical operators: and \ or \ not in \ in

Logical, and comparison operators, the result returns a Boolean value, returns a value of True True, False False

Implementation of priority:

1, first calculated () contents inside

2, no parentheses, the order of execution, from front to back

3、

The result is True with or ====> True

The result is the True and ====> continue to judge

And the result is False or ====> continue Analyzing

The result is False and andr ====> False

Second, the basic data type

ctrl + mouse to select a data type, see all the functions included in the data type

1 digital int

a="123"
b=int(a)
b=b+100
print(type(b),b)

  Interpretation: a speaking character string is converted to a digital b, type (b) you can see the data type b

a="123a"

b = int (a) ######## can convert the string to numeric, the letters may not

1) The common Data Type

bit_length (), on behalf of current needs at least a few numbers in binary representation

age=10
v=age.bit_length()
print(v)

2 string str

Common Data Type

2.1 captalize, the first letter represents the output of capital

test="alex"
v1=test.capitalize()
print(v1)

2.2 caseflod, represent all characters to lower case

test="alEx"
v1=test.casefold()
print(v1)

 2.3 center, represents a character width setting, and the contents center, # 20 generations total length, the space can be used on behalf of that * instead of *, a * may be any character, * fill gaps when no character width

test="alEx"
v1=test.center(20,"")
print(v1)

2.4 count, represents the seek sequence from a string lookup starting position may be provided: start and end positions.

test="alExalExrrfrgddealEx"
v1=test.count("Ex",5,20)
print(v1)

  Calculate the number of the current character appears, you can start looking from No. 5, the end of the first 20 to find

2.5 endswith and startswith, indicates what is beginning or ending, true and false judgment

test="alExalExrrfrgddealEx"
v1=test.startswith("a")
print(v1)
test="alExalExrrfrgddealEx"
v1=test.startswith("b")
print(v1)
假

2.6 find, looking back from the beginning of representation, to find after the first one, whichever subscript / Location

= Test " alExalExrrfrgddealEx " 
V1 = test.find ( " Ex " , 7,20 )
 Print (V1) 

Results: 20 
Start found from the bit 7 to less than 20 a first end position to find Ex appears, it is returned subscript

Note: -1 for not found

2.7 format, the representative format, a string placeholder is replaced with the specified value

 

3 in list

 

4-tuple tuple

 

5 Dictionary dict

 

 

6 Boolean value bool

 

Guess you like

Origin www.cnblogs.com/xucuiqing/p/11456566.html