Python Introductory Learning-----variables and underlying types P day

Source: Internet
Author: User

Variables and data types for Python

1, Python variables do not need to define the data type in advance, can be changed dynamically

2.Python is all object, variable is an object, has its own properties and methods

We can pass

To see the type of the variable: variable name. __class__

Method of calling Variable: variable name. Method ()

#!/bin/env Python#coding:utf-8#type prints out the type of data print type (1) Print type (1.0) Print type ("HelloWorld") #虚数 such as 12j a = 12j + 1print Aprint type (a) # Division and remainder print "5/3 =%d"% (5/3) print "5 percent 3 =%d"% ( 5% 3) #进制数字打印print "%d,%o,%x"% (10,10,10) #查看变量的类型a = "Hello World  " Print a.__class__# method for calling variables print a.split ()

Tuple (tuple)

#!/bin/env python#coding:utf-8# In addition to strings and numeric values, Python provides another 4 important basic types: #元组, lists, collections, and dictionaries. #元组 (tuple): Non-changing data series A = ("First", "second", "third") #输出元组print (a) #打印元组的长度print ("A len:%d"% Len (a)) #遍历元组print ("%s%s% S "% (A[0],a[1],a[2])) #元组中的一个元素被另一个元组引用b = (A," four ") print (b) print ("%s%s%s "% (B[0][0],b[0][1],b[0][2],b[1])) # tuples can be Contains various types of data, but after creation, it is no longer possible to change the # tuple to be immutable. (strings are immutable after they are created, and those that seem to change # their operations actually create new strings) #下面的书写将会报错a [1]  = 3


Python Getting Started learning-----variables and underlying types P day

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.