Numbers (digital)
Numeric data types are used to store numeric values.
They are immutable data types, which means that changing the numeric data type assigns a new object.
int = Tenprint int10
int = 20
print int
20
Python supports four different types of numbers:
- int (signed integral type)
- Long (longer integer [can also represent octal and hexadecimal])
- Float (float type)
- Complex (plural)
int |
Long |
float |
Complex |
10 |
51924361L |
0.0 |
3.14j |
100 |
-0x19323l |
15.20 |
45.j |
-786 |
0122L |
-21.9 |
9.322e-36j |
080 |
0xDEFABCECBDAECBFBAEl |
32.3+e18 |
.876j |
-0490 |
535633629843L |
-90. |
-.6545+0j |
-0x260 |
-052318172735l |
-32.54e100 |
3e+26j |
0x69 |
-4721885298529l |
70.2-e12 |
4.53e-7j |
Long plastic mind directly with L, in case of mixing with the number 1
There are two types of plural definitions
#1 Complex
Copl=10+0.323232j
(10+0.323232J)
#2 complexcops=complex (10,0.3232j)
Print cops
(9.6768+0J)
Python string
A string or series (string) is a string of characters, consisting of numbers, letters, and underscores.
The Python string list has 2 order of values:
- Left-to-right index starts at default 0, with a maximum range of 1 less string lengths
- Right-to-left index starts with default-1, the maximum range is the beginning of the string
str="12312312"print str[0] # The first character in the output string print Str[2:5] # The string from the third to the fifth in the output string print str[2:] # Output a string starting from the third character print str * # output two times
Python list
The list is the most frequently used data type in Python.
A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and even strings that can contain lists (so-called nesting).
' 12321 ' ' Hi ' ]print list[0] # The first element of the output list print list[1:3] # Print list[2:] # output all elements from the third start to the end of the list print list
Python tuples
A tuple is another data type, similar to a list.
The tuple is identified with a "()". The inner elements are separated by commas. However, tuples cannot be assigned two times, which is equivalent to a read-only list.
' 1122 ' ' Hello ' )print tuple[0] # The first element of the output tuple print tuple[1:3] # print tuple[2:] # Output All elements from the third start to the end of the list print Tinytuple * 2 # output tuple two times
Python Meta Dictionary
The Dictionary (dictionary) is the most flexible built-in data structure type in Python, except for lists. A list is an ordered combination of objects, and a dictionary is a collection of unordered objects.
The difference between the two is that the elements in the dictionary are accessed by keys, not by offsets.
The dictionary is identified with "{}". A dictionary consists of an index (key) and a value corresponding to it.
Dict ={}dict[' One'] ="Hello"dict[2] =" World" Printdict[' One']#the value of the output key is ' one 'PrintDICT[2]#the value of the output key is 2PrintDict#output a complete dictionaryPrintDict.keys ()#Output All keysPrintDict.values ()#Output All Values
Python Data type conversions
Sometimes, we need to convert the data-built type into the data type, and you just need to use the data type as the function name.
The following several built-in functions can perform conversions between data types. These functions return a new object that represents the value of the transformation.
function |
Description |
int (x [, Base]) |
Convert x to an integer |
Long (x [, Base]) |
Convert x to a long integer |
Float (x) |
Convert x to a floating-point number |
Complex (real [, Imag]) |
Create a complex number |
STR (x) |
Convert an object x to a string |
REPR (x) |
Convert an object x to an expression string |
eval (str) |
Used to evaluate a valid Python expression in a string and return an object |
Tuple (s) |
Converting a sequence s to a tuple |
List (s) |
Convert the sequence s to a list |
Set (s) |
Convert to mutable Collection |
Dict (d) |
Create a dictionary. D must be a sequence (key,value) tuple. |
Frozenset (s) |
Convert to immutable Collection |
Chr (x) |
Converts an integer to one character |
UNICHR (x) |
Converts an integer to a Unicode character |
Ord (x) |
Converts a character to its integer value |
Hex (x) |
Converts an integer to a hexadecimal string |
Oct (x) |
Converts an integer to an octal string |
Start learning Python-python variable types