Getting started with python (5): data types

Python is an object- oriented language, so there is no need to declare the variables and categories that need to be used before using it.

One, string string

The string is placed in ('') or (" ").
If you want the connection string, simply add up to.

string1 = 'Hello'
string2 = 'Python'
string3 = '!'
string4 = string1 + ' ' + string2 + string3
print(string4)

Insert picture description here
Note:
If the string itself contains single quotation marks (') or double quotation marks ("), it should be preceded by a right slash (\) .

string = "I\'m caroline. I love \'python\'!"
print(string)

Insert picture description here

Two, number

Number types are used to store numeric values. Here are two commonly used types of numbers: integer (int) and floating-point (float). Floating-point numbers are composed of integer and decimal parts.

Two types of numbers can be converted to each other :
integer> floating point number: add "float"
floating point number in front of variable> integer: add "int" in front of variable

intx = 7
floaty = 7.5
print(intx)
print(floaty)

trans_inty = int(floaty)
trans_floatx = float(intx)
print(trans_inty)
print(trans_floatx)

Insert picture description here

Three, list, tuple, set, dictionary

See my blog: Getting started with python (3): Data structure
Getting started with python (3): Data structure

Guess you like

Origin blog.csdn.net/qq_45154565/article/details/109318648