Python full stack __python difference, input, if, while

Source: Internet
Author: User

First, the initial computer

CPU memory hard Disk operating system

CPU: Is the brain of the computer, central processing Unit, mainly responsible for data operation and calculation, is the computing center.

Memory

Memory: Temporarily stores data for use by CPU operations.

Advantages: Fast reading speed.

Disadvantages: Small capacity, high cost, power loss disappears.

Hard disk: Long-time storage of data, large storage capacity. such as 500G, 1T, 2T. Can store large children, small video.

Advantages: Large capacity, low cost, power failure does not disappear.

Disadvantage: Slow reading speed.

Operating system: Provision of system hardware resources, in collaboration with the operation of the hardware.

Existing operating systems such as Windows, Linux, Cenos, Mac ...

2. Python development History and impact

Python language Features: Beautiful, clear, simple.

2008 Python 3.X version generated

The difference between Python version 2.x and Python 3.x version

Python version 2.X

1, source code is not standardized, source confusion, duplicate code more.

2, the default encoding mode ASCII code.

3. print ' content '/print (' content ').

Python version 3.x

1, re-source code, source code specifications, beautiful, clear, simple.

2, the default encoding method Utf-8.

3, print (' content '). Brackets and quotation marks are the citation punctuation marks.

#-*-Encoding:utf-8-*-. Change the default encoding to print in Chinese.

#-*-Encoding:utf-8-*-print (' Hello China ')

3, the current language classification

Compiled type:

Compile the code all at once into a binary number before running.

Advantages: High execution efficiency.

Disadvantage: Development efficiency is slow, can not cross the platform.

Representative language: C language and so on.

Explanatory type:

The code is interpreted line by row, interpreted as binary code, and then run.

Advantages: The development efficiency is high, the third party library is many, can cross the platform.

Disadvantage: Low execution efficiency.

Representative language: Python, etc.

4. Types of Python

The Python language runs

Windows key +r the command to run the window, then the window input cmd, press ENTER. Enter the python space file path to enter.

5. Variables

Variables: Store the computed intermediate results for subsequent code use.

Variable setting rules:

1. Must be any combination of letters, numbers, underscores.

2, can not be the beginning of the number.

3. Cannot be a python keyword.

And, as, assert, break, class, continue, Def, Del, elif, else, except, exec, finally, for, from, Global, if, import, in, is, Lambda, not, or, pass, print, raise, return, try, while, with, yield

4, the variable cannot be Chinese.

5, the variable can not be too long.

6. Variables are descriptive.

Variable naming methods:

Hump Body:

Ageofoldboy = 56NumberOfStudents = 80

Underline: (recommended)

Age_of_oldboy = 56number_of_students = 80

Constant: The amount that has remained constant. The default all uppercase variable is a constant.

All uppercase variables are constants and are placed at the beginning of the file.

For example: Social Security number, π, etc.

Comments:

Help you understand other people's code and recall your own code.

Single-line Comment: #

Multiline Comment: ' commented content ' or ' annotated content '.

Underlying data type:

int: number, Integer. For calculation, + 、-、 *,/,% (for redundancy).

STR: String. In Python, it is the string that is quoted in quotation marks.

Print (' This is a string ') print ("This is a string")

msg = "The Moonlight before the bed, suspected to be ground frost." ‘‘‘
Print (msg)

msg = "'

Content ""

The contents of the three quotation marks are printed out in the original format.

String: Can be added, can be multiplied.

+ Plus (splicing):

STR + str: concatenation of strings.

MSG1 = ' old boy education ' MSG2 = ' is the best training institution ' print (MSG1 + msg2)

Multiply

STR * INT

msg = ' strong ' Print (MSG * 8)

Bool:ture false two states: The Judgment code is true or FALSE.

Print (3 > 2) print (3 > 4)

Print (' true ') print (true)

To determine the datatype type type ()

Print (' Ture ') print (Ture) print (' Ture ', type (' Ture ')) print (Ture,type (Ture))

Name = input ("Please enter your name:") Age = Input ("Please enter Ages:") print (Name,age,type (name), type (age))

6. Input user enters Python2. The difference between x and python3.x: python2x:
Raw_input ()
Input () is equivalent to eval ()
Python3x:input () 7, if

C Language:

if (condition) {result}

Python:

If condition:    result

Print (111) If 3 > 2:print (666) print (333)

If condition:    result else:    Pass

Name = input ("Please enter your name:") If name = = "Rajah":p rint ("Old iron, no problem!") ") Else:print (" Ill-governed ... ")

If condition:    passelif Condition:    Pass
Elif Conditions:
Pass

num = Int (input ("Please enter your selection:")) if num = = 4:print ("Lunch I please!") ") elif num = = 5:print (" Supper I please! " ") elif num = = 6:print (" Big night Health Walk! ") ")

If condition:    passelif Condition:    passelif Condition: passelse:    Pass

num = Int (input ("Please enter your selection:")) if num = = 4:print ("Lunch I please!") ") elif num = = 5:print (" Supper I please! " ") elif num = = 6:print (" Big night Health Walk! ") Else:print ("Give you a chance to catch up!") ")

score = int (input score)) If score >:p rint ("I rub, up to 100 points ...") Elif score >=:p rint ("A") elif score >=:p RI NT ("B") elif score >=:p rint ("C") elif score >=:p rint ("D") else:print ("Too stupid ... E ")

If condition: else:passelse:if. Else: ...

NUM1 = input ("Enter Number") if Num1 = = "3": num2 = input ("Please enter the number again") if num2 = = "5":p rint ("This can be guessed right!") Else:print ("Keep trying!") ")

    

8. While
While condition:    Pass

While True:p rint ("Loyalty") Print ("Pink Memory") print ("Cool") print ("Wind Up")

Flag = Truewhile Flag:p rint ("Loyalty") Print ("Pink Memory") print ("Cool") print ("Wind up") flag = False

Flag = Truewhile Flag:p rint ("Loyalty") Print ("Pink Memory") print ("cool") flag = Falseprint ("First time")

Count = 1flag = Truewhile  flag:p rint (count) count +=1if count = = 101:flag = False

Count = 1while Count < 101:p rint (count) Count + = 1

Count = 0while Count < 101:p rint (count) Count + = 2

Count = 0while Count < 101:if count% 2 ==0:p rint (count) Count + = 1

To terminate a loop:

1, change the conditions.

2, break. (Direct end loop)

While True:p rint (111) Print (222) breakprint (333) print (666)

Key words:

Break: Jump out of the loop body directly

Continue: End this cycle and continue the next cycle.

While True:p rint (111) Print (222) continueprint (333) print (666)

#break While Loop calculates the 1+2+3+4...+100

Count = 1sum = 0while Count <101:sum = sum + countcount +=1print (sum)

Count = 1sum = 0while true:sum = sum + countcount +=1if count = = 101:breakprint (sum)

Python full stack __python difference, input, if, while

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.