2019.7.30 learning content and quizzes notes

Basic data types

Variables are used to describe the state of things in the world

type of data

NOTE: Different types of variable values ​​described by different kinds of data types

Digital Type

Integer (int)

Defined way :

height1 = 180
height2 = int(180)
print(height1)
print(height2)

Role : age, identity card number, height, weight, etc.

Usage : +, -, *, /, rounding, modulo idempotent

a = 1
b = 2
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a//b) #取整
print(a%b)  #取余
print(a**b) #幂

Note : python if it is a cell phone, pip is the software housekeeper, cmath Software is equivalent to a tube at home

Float

Defined way :

salary1 = 3.2
salary2 = float(3.2)
print(salary1)
print(salary2)

Role : Salary and other

Usage : +, -, *, /, rounding, idempotent

String type

String: String together is to

Defined way :

Single, double or triple quotation marks character wrapped together, it is noted that: the character in quotation marks newline three, and single or double quotation marks in the character row does not change.

Role : name, gender, appearance, saying, etc. (can only be used when describing sex gender, do not use sex, because sex insulting)

Note : 1. If there are quoted string, were not wrapped quoted string and the string is the same as quoted

2. String multiplication can only be multiplied by digital

Usage: + string can only be used, and the logical comparison * ( Note : When adding the string, if the different data types can not be added)

Care regardless of the end : that is, when the string slices, place a note, or that is a principle: when a string of cut, sliced end position, but does not include the end of that position. "Formulas care regardless of the end."

List type (list)

Effect : quite a list container object is used to store a plurality of types of data (can be of any data type)

Definitional manner : a list type is the definition of a variable, it should be noted that any type of value are separated by a comma within [], such as:

list = ['read','run','music']
print(list)
print(list[0])
print(list[0:2])

Usage : Because the deposit method is not an end, to take is the purpose, we can use the list index value, bearing in mind the index number from 0

)

Dictionary types (dict)

I think with the type of list (list) like, list type is used to store more data, but our main aim is to take

First, a dictionary of definitions manner : key-value pairs separated by a comma in the {}, then there will need to explain two names:. 1 key (descriptive sense generally used type indicates string, can not be used dictionaries and lists) ;

2.value (meaning representations of numbers) may be any type of data

Example:

nick_info_dict ={'name':'nick','height':180,'weight':140,'age':18
                'hobby_list':['read','run','music']}
print(nick_info_dict['name'])
print(nick_info_dict['age'])
print(nick_info_dict['hobby_list'])
print(nick_info_dict['hobby_list'][1])
                

Usage : dictionary is no longer dependent on the way the index value, but rather rely key, to obtain the value corresponding to the key value through the [key]

Boolean type (bool)

Boolean type generally occurs as a result of conditions not directly use

True to display logical judgment

It is judged that the display is not logical False

python中除了0/None/空(空字符/空列表/空字典)/False之外所有数据类型都自带布尔值为True

unzip

Definitions : decompression can be understood: the supermarket package is put together more merchandise, decompression is actually unpack multiple disposable goods out

Note : 1. Sometimes we decompress values may be we do not want, you can use the underline (convention) of

2. asterisk + underscore (_ *) in front of all will fall, and indicates that not all

3. Unzip the number of elements in an object, you must take a number of

Interaction with the user

I understand the interaction with the user is to make the software as a user with AC operation

Here that user interaction is input

With print is representative of the output, and input represents an input, it is to allow the user to enter the corresponding information

inp = input('请输入你的手机号:')

username = 'nick'
pwd = 123

Finish

Guess you like

Origin www.cnblogs.com/chmily/p/11272313.html