Python-variable definition and data type conversion

1. python variables

<1> Variable definition: The variable name is defined only when it appears for the first time. When it reappears, instead of defining the variable, the previously defined variable is used directly. A variable is an address space. When a value is assigned to a variable, this value is put in, and the memory space is released when the value of the variable is deleted.

<2> Variable naming rules: Variables are composed of numbers, letters, and underscores. They cannot start with a number, and cannot be the same as keywords.
Such as: first_name (correct), first name (error), 4first (error) print, etc.

<3> Representation of variables: big camel
peak method (commonly used) and small camel peak Big head peak is the capitalization of the first letter of each word: FirstName
small head peak is the lowercase of the first word, and subsequent words capitalized: firstName

<4> Note the naming of variables: try to be as famous as possible

Example 1:
Insert picture description here
Insert picture description here
Test questions: The
Insert picture description here
Insert picture description here
results are as follows:
Insert picture description here

2. Data type

<1> int
Python2 has integer and long integer types, Python has no long integer type

Among python2: In
Insert picture description here
python3:
Insert picture description here
<2> float decimal type, floating point type
Insert picture description here
<3> str string
Insert picture description here
Insert picture description here
Insert picture description here
<4> bool boolean True (true), False (false)
Insert picture description here

3. Data type conversion

Note: Integer and floating point types can be converted to each other. Both integer and floating point types can be converted to character types, but character types cannot be converted to integer or floating point types.
Insert picture description here

Published 41 original articles · praised 0 · visits 1697

Guess you like

Origin blog.csdn.net/qq_44749796/article/details/105603114