The first is assignment, various types
#coding =utf-8#!user/bin/pythonimport sysstring = ' Hello ' integer = 1000floater = 1.00print Integerprint Floatersys.stdout.write (string + ' \ n ')
Python has five standard data types:
- Numbers (digital)
- String (String)
- List (lists)
- Tuple (tuple)
- Dictionary (dictionary)
Defining variables and Unregistering variables
#coding =utf-8#!user/bin/pythonimport sysvar1 = 1var2 = 2var3 = 3print var1print var2print var3del var1print var1print var2 Print Var3
Python supports four different numeric types:
- int (signed integral type)
- Long (longer integer [can also represent octal and hexadecimal])
- Float (float type)
- Complex (plural)
Python string
#coding =utf-8#!user/bin/pythonimport sysstring = ' ilove ' Print string[1]print string[2]print string[3]print string[4] Print String[1:5]
Python list
#coding =utf-8#!user/bin/pythonarray = [' 111 ', 11, ' Hello ', 22,33,10.2]print array[0]print array[2]
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, an element cannot be assigned two times, which is equivalent to a read-only list
#coding =utf-8#!user/bin/pythonyuanhzu = (' xxx ', ' world ', 10,2.02) print yuanhzu[0]print yuanhzu[1]yuanhzu[1] = ' Hello ' Print yuanhzu[1]
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.
#coding =utf-8#!user/bin/pythonarray = {}array[' key '] = ' name ' array[' value '] = ' Jack ' Print Arrayprint array.keys () print array[' key ']print array.values () arr = {' One ': ' xx ', ' x ': ' yy '}print arr.values () print Arr.keys ()
Python Data type conversions
#coding =utf-8#!user/bin/pythona = 1b = 2c = ' 222 ' Print A + bprint int (c) + 22
Python Variable Type