Basic types of Python basics, looping

Source: Internet
Author: User

1.python basic types are: numbers, strings, lists, tuples, dictionaries.

(1) The number type has the following types:

int (signed integral type)
Long (longer integer [can also represent octal and hexadecimal])
Float (float type)
Complex (plural)

(2) A string: A String or Series (string) is a series of characters consisting of numbers, letters, and underscores.

(3) List: A list is the most commonly used Python data type, which can appear as a comma-separated value within a square bracket.

(4) Tuples: A python tuple is similar to a list, except that the elements of a tuple cannot be modified. Tuples use parentheses, and the list uses square brackets.

(5) Dictionary: A dictionary is another variable container model and can store any type of object. The key must be unique, but the value does not have to be.

2.Python loops often have a for loop and a while loop.

The above example code and the calling code are as follows:

he.py

#Coding=utf-8#Basic TypedefShow ():#Digitalage=10Print("Age :"+Str (age))#stringUname="Tom"     Print("uname:"+uname)Print("The first charset of uname:"+uname[0])#Listli1=["Joyet1","tom1"] Li1.remove ("tom1") Li1.append ("Mike1") Li1.insert (1,"yy1") Li1num=Len (li1)Print("li1 Length:"+str (li1num))#list for loop     forXinchLi1:Print("the list values are:"+x)#Meta-groupLi2= ("Joyet2","Tom2") J=0 whilej<Len (li2):Print("the tuple values are:"+Li2[j]) J+=1#Dictionaryli3={"UID":"1","uname":"Joyet"}    Print("Dictionary uid:"+li3["UID"])     forDickey,dicvalueinchLi3.items ():Print("Key:"+dickey+", the value is:"+dicvalue)

Calling code:

 from Import *>>> Show () Age:uname:tomthe First CharSet of uname:tli1 length:3 list values are: Joyet1 List value is: Yy1 list value is: Mike1 tuple value is: Joyet2 tuple value: Tom2 dictionary uid:1key:uid, Value:1key:uname, Value: Joyet> >>

Basic types of Python basics, looping

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.