Python Basics 3-variables and numbers

Source: Internet
Author: User
Tags mathematical functions

1, the Python variable does not need to declare, its assignment operation is both the variable declaration and the definition process;
2, each variable in Python must be assigned before use, the variable will be created after the value is assigned;
3, the python variable is stored in the memory value, if the variable is assigned to the memory of the corresponding value is directly pointed to the value, if the value is not present in memory, the creation of a variable will automatically allocate a piece of memory space to the corresponding variable (can be verified by the built-in function ID (variable name));
4, variable assignment is done with an equal sign (=), the left is the variable name, the right is a value, and Python allows multiple variables to be assigned simultaneously (same value and different value);
5, if you want to let the same variable store different data, do not need to delete the original variable can be directly assigned value.

C:\windows\system32>python
Python 2.7.5 (default, May, 22:43:36) [MSC v.1500 + bit (Intel)] on win
32
Type "Help", "copyright", "credits" or "license" for more information.

>>> A = 10
>>> ID (a)
19573884
>>> B = 10
>>> ID (b)
19573884
#内置函数type () that is used to query the type of the variable
>>> type (a)
<type ' int ' >

>>> A = b = 2
>>> ID (a)
19573980
>>> ID (b)
19573980

>>> a,b,c=1,2,3
>>> ID (a)
19573992
>>> ID (b)
19573980
>>> ID (c)
19573968


Python has five standard data types:
Numbers (digital)
String (String)
List (lists)
Tuple (tuple)
Dictionary (dictionary)

Numeric data types are used to store numeric values, and numeric objects are created when you assign a variable
Python supports four different numeric types:
int (positive or negative integer, without decimal points.) )
Long (an integer of infinite size, an integer that is finally an uppercase or lowercase l)
Float (float type)
Complex (plural)

You can delete single or multiple objects by using the DEL statement, for example:
Del T
Del T1,t2

>>> t=2
>>> t1=3.3
>>> t2= 3L
>>> t3=1+3j

>>> type (t)
<type ' int ' >

>>> type (t1)
<type ' float ' >

>>> type (t2)
<type ' Long ' >

>>> type (T3)
<type ' Complex ' >

--------------------------------------

#Python数据类型转换

Data type (variable name), such as:

S=float (t)

Print S

Mathematical functions commonly used in numeric types:

CMP (x, y) #比较两个数大小 if x < y returns-1 if x = = y returns 0 if x > y returns 1

Max (x, y, z,....) #返回给定参数的最大值, the parameter can be a sequence.

Min (x, y, z,....) #返回给定参数的最小值, the parameter can be a sequence.

Shuffle (list) #将序列的所有元素随机排序

Python Basics 3-variables and numbers

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.