Python Learning Path (ii)

Source: Internet
Author: User

Go on with your last study.

(a) The first contact is a variable, first define a variable, in Python do not need to declare a variable in the C language, but can be directly assigned to the value.

Name= "Xiaoming"

One thing to note here is that assigning values to a variable must be double-quoted, and if not, name equals another variable xiaoming.

Name=xiaoming   #这不是赋值

Also, be aware of the following three points when naming variables:

1. Variable names can only be any combination of letters, numbers, or underscores

2. The first character of a variable name cannot be a number

3. The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

(ii) on the input

In Python3, the input is defined as a string (str), because Python is a strongly typed definition unless it is forced to transform.

Age=input ('How old is')print(type (age))

If you enter a 22 here, the printed result will not be an int, but a str, if you need to convert the type, you need this:

Age=int (Input ('How old is you')

Here's the data type, there are several types of data in Python;

1, number. The numbers are divided into several

int (integral type)

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807long (Long integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but in fact, because of limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Float (float) floats are used to process real numbers, that is, numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers. Note: Small number pools exist in Python:-5 ~ 257 2, Boolean true or False 1 or 03, string

Hello World

(c) operator

Python operators a lot, I do not list here, the online experts have written very detailed, here to everyone a Web site to refer to

Http://www.runoob.com/python/python-operators.html

(iv) Summary of assorted

A "the biggest difference between Python2 and Python 3 is that it supports Chinese in 3!"

B "Execute the following code, the resulting is not b,b

Name='a'name2=namename='b'print ("  name","name2")>>>b, A

Because in the assignment process, the value of name2 is the value of the copied name in memory A, then in memory, then name changed, but Name2 's in-memory values did not change, so the final output was b,a
C "In Python3, the general default is Utf-8, if you want to let him use Utf-8 when running, you can enter the following code

# -*-coding:utf-8-*-

This will automatically use the Utf-8 if it is placed in a different environment (such as Python2).
D "single-line comment with #

Multi-line annotation with "'"

single-  line comment # print (name) Multi-line comments " " name= ' A ' print (name) " "

Python Learning Path (ii)

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.