Python Variable Type

Source: Internet
Author: User
Tags python list

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.