Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Python basic course-detailed explanation of data types
Python basic course-detailed explanation of data types
Python provides a variety of data types to store data. Among them, data types include: string, Boolean type, integer, floating point number, number, list, tuple, dictionary and date.

1, string

A=' This is the string' print aa='' This is the string' print aa='' This is the string, this is the string''' Print a.

boolean type

Often used for circular judgment.

integer

A=int(80.974 1) prints a.

floating-point number

A= float(80.974) print a.

Conversion of character types

int(x print L 1 L2 =[' ABC ']print L2 L3 =[" a "," b "," c "]print L3L = list(" Python ")print L[0]print L[3]print L[- 1]

Python tuples are similar to lists, except that the elements of tuples cannot be modified; Use parentheses () for tuples and [] for lists; Tuple creation is simple, just add elements in brackets and separate them with commas (,), for example:

Tup 1 = ('physics',' chemistry',1997,2000);

tup2 = ( 1,2,3,4,5);

tup3 = "a "," b "," c "," d ";

Dictionary is the most flexible built-in data structure type in python except list. A list is an ordered combination of objects, while a dictionary is an unordered collection of objects. The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.

A dictionary consists of keys and corresponding values. Dictionaries are also called associative arrays or hash tables. The basic syntax is as follows:

Dict = {'Alice':' 234 1',' Beth':' 9 102',' Cecil':' 3258'};

Time date

Import time, date and time. Local time = time. Local time (time. time ()) Today = datetime. date. Today () Print "Local current time:", today.