Python basic data type (detail)

Source: Internet
Author: User

#基本数据类型


#数值类型 4

‘‘‘

Shaping int


Float type float


boolean bool


Complex Type Complex

‘‘‘

#整形

A = 0

b =-1

Print (Type (a))


#浮点型

F = 1.1

F1 =-1.1

Type (f)


#布尔型

t = True #1

f = False #0


#复数型 complex, the imaginary part can only be used J

c = 1 + 2j


# # # #数值运算

A = 2

b = 2.5

A + b

A-B

A * b

A/b # 0.8

a//b # (evenly divisible, rounded down)

2% #取余

9**2 # 9 Squared

3**3 # 3*3*3



# # # #序列类型

‘‘‘

String STR is not mutable

List variable

Ganso Tuple not variable


‘‘‘

s = ' s '

#s = ' ss ' ss ' # ' SSSS '

S1 = "SS"

S3 = "ddd ' AA '" #当我们 with double quotation marks when there are single quotes inside the string

S4 = "AAA"

S5 = "BBB"

Ddd

‘‘‘


# #注释 Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

‘‘‘

1. #号, can not be wrapped, #后面全部被注释了

2. Three quotation marks, can support line wrapping


‘‘‘


#变量的命名规则:

‘‘‘

1. Variable name must be, letter, underscore, number composition

2. Cannot start with a number

3. Cannot use keywords

‘‘‘


#555 = ' A ' ERROR

#我 = ' A ' kanji also line, do not conform to the specification

#False = 1 Error


Import keyword

Keyword.kwlist



# False = = 1

‘‘‘

An equals sign represents a complex value, = =, which determines whether it is equal


‘‘‘


# #list List

Li = [1,2,3,4]



#tuple Yuan zu

Tu = (1,2,3,4)

TU2 =

TU3 = (1,)


###### Index

Li =[1,2,3,4,5]

Tu = (1,3,4,5)

S= ' ASD '

LI[0] #取出第一个元素, index is starting from 0


# #正向索引

LI[1]

TU[2]

S[0]

# # #反向索引,-1: Take out the penultimate one. -2: Take out the penultimate one

LI[-1]

S[-1]

Tu[-2]



#切片: Take out a small segment (left closed right)


Li[0:2] #[1, 2], the left border can be taken, the right border cannot be taken

S[1:2]

Tu[1:3]


#步长

Tu[0:4:3] # (1, 5)


tu[:] # Default is from 0-last


Tu[1:4]

Tu[1:4:] #默认步长为1


tu[::] # # #全体输出



#负步长

TU[3:1:-1]

Tu[3:1:-2]


#赋值运算

Li *= 2

A +=1

A *= 4


#成员运算


#in determine whether the

' s ' in S # True

' m ' in S # False


#not in to determine if it is not

' s ' not in S # False

' m ' not in S # True


########### #3 variable Non-volatile

ID (1) #如果id, that means the same memory address, which means the same object


This article from "a dish can no longer dish of small rookie" blog, declined reprint!

Python basic data type (detail)

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.