WIN10 installation Python3 and Python2, data types, formatted output, operators

Source: Internet
Author: User

installation of Python3 and Python2 under Win10

Download the official website address: https://www.python.org/downloads/windows/

    • Install Python3:

After the installation is complete, enter CMD at the beginning to test if the Python installation was successful.

Input: Python-v ———— > Pip-v ———— > Pip

    • Install Python2:

After the installation is complete, open the command prompt page that you opened earlier to test whether Python was installed successfully.

Input: python-v ———— > Pip-v

coexistence of python3.x and python2.x

    • Discover question 1: How do you make python3.x and python2.x coexist?

viewing system environment variables

The environment variables are found to be sequential:

Enter the python3.x installation directory, copy the Python.exe and rename it to Python3.exe. (Be sure to copy one, otherwise input pip-v time will be error)

Look again, the error disappears:

    • Question 2: How can I enter Python, the default display is python3.x, when the input python2, display as python2.x?

Enter the installation directory of the python2.x, also copy the Python.exe and rename it to Python2.exe; (be sure to copy one, otherwise input pip-v will be an error)

Then re-edit the location of the environment variable, using the Move up to modify the order of the python3.x.

Check again:

Data Type

data Type--numeric type>>>age = 21
>>>name = ' Wu Qianqian '
>>>type (age)
<class ' int ' >
    • 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~9223372036854775807
    • 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.

Cases:
>>> a= 2**64
>>> type (a) #type () is a way to view data types
<type ' Long ' >
>>> B = 2**60
>>> type (b)
<type ' int ' >

Attention:
① since Python2.2, if an integer overflow occurs, Python automatically converts the integer data to a long integer, so there is no serious consequence of not adding the letter L after long integer data.
② no longer has a long type in Python3, it's all int.
③ in addition to int and long, in fact, there are float float type, complex type.


data Type--string type
    • String type
In Python, the quoted characters are considered to be strings.
Cases:
>>> name = "Alex Li" #双引号
>>> age = "#只要加引号就是字符串"
>>> Age2 = #int
>>>
>>> msg = ' My name is Alex, I am years old! ' #3个引号也可以
>>>
>>> hometown = ' Shandong ' #单引号也可以
Attention:
① single and double quotes are no different. However, it is necessary to consider the use of single and double quotation marks if you encounter the following situation.
msg = "My name is Alex, I ' m years old!"

The function of ② multiple quotes is that multiple-line strings must be in multiple quotes.
msg = "'
Today I want to write a little poem,
Sing the praises of my deskmate,
You see his black short hair,
It's like a fried chicken.
‘‘‘
Print (msg)

    • Concatenation of strings
Numbers can be subtraction and so on, but strings can be used only for "add" and "multiply" operations.

The concatenation of strings can only be a string between the two, and cannot be spliced with numbers or other types.

data Type--string typeThe Boolean type is simple, with two values, a true (true), and a false (false), primarily for logical judgments.

For example, there are now 2 values, a=3 and b=5, if let's say a>b is established? Of course we know it doesn't, but the question is, how does a computer describe it as a non-establishment? or let the computer to describe a< B is established? Why do computers describe this condition? Because then we can do different things according to the result of the condition. Like what:

If a > B
Print (A is bigger than B)

Else
Print (A is smaller than B)

formatted output

Existing practice needs, ask the user's name, age, work, hometown, and then print into the following format:

------------Info of-----------
Name:
Age:
Job:
Hometown:
-------------End-----------------
Method One: Character stitching
#定义变量
Name = input ("Name:") Age = Input ("Age:") job = input ("job:") hometown = input ("Hometown:")

#拼接 print ("---------info of", Name, "-------------" Print ("Name:", name) print ("Age:", age) Print (" job:", job) print ("Hometown:", hometown) print ("---------End of-------------")

However, it is difficult to implement the output of this format by using the character stitching method.


Method Two: The format to be printed first, will be inside some need user input, no way to predict the information, with placeholders, and then the string of placeholders and external variables to do a mapping relationship.

    #定义变量
Name = input ("Name:") Age = Int (Input ("Age:")) #将字符串类型转为数字类型 job = input ("job:") hometown = input (" Hometown: ")
    #格式化
info= " ---------info of%s------------- name:%s #代表name age:%d #代表age Job: %s #代表 Job
hometown:%s #代表hometown
    ---------End of-------------
"% (Name,name,age,job,hometown)
Print (info)

Attention:
%s=string character string placeholder
%d=digit Digit Placeholder
%f=float Decimal Type placeholder
Input is typed by default in string type and can be viewed using print (Type (   )).


Operator
There are many kinds of computing that can be done by computer, it is not only subtraction so simple, the operation can be divided into arithmetic operation, comparison operation, logical operation, assignment operation, etc. by kind.
    • Arithmetic operations
Suppose a=10, b=20

    • Comparison operation
Suppose a=10, b=20

    • Assignment operations
Suppose a=10, b=20

    • Logical operations
Suppose a=10, b=20


WIN10 installation Python3 and Python2, data types, formatted output, operators

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.