? Python Learning Diary: Day1

Source: Internet
Author: User

1, the Computer Foundation

CPU: Equivalent to the human brain, used for computing. Memory: Store data, run fast, high cost, power loss data disappear.
HDD: SSD (FAST), mechanical hard drive (with pointer). Storing data, requiring long-term data retention, important documents
Open QQ Process: Click-hard disk-call data to memory-register-cpu-transmit data to the monitor.
Operating system

2. Python history
(1) Birth: 1989 Christmas, Van Rossum in Amsterdam in order to pass the time, developed a new script interpreter program-python.

(2) Python features: Beautiful, clear, simple.

(3) macro-Python2 and Python3 differences:
Python2: The source code is not standard, chaotic, repeated codes are many.
Python3: Unify, Standard, remove duplicate code.

(4) 2017 programming language rankings:

(5) What companies are using Python

  

3. Python Environment

(1) Advantages and disadvantages of compiled and interpreted languages

Compile: All program code is compiled into binary files at once (it involves the operation of data compiled type, such as C + +, c)
Advantages: Fast execution speed.
Cons: Low development efficiency (need to compile all again after a bug), not cross-platform (incompatible).
Interpreted: The interpretation of a line when the program executes. (such as: Python, PHP)
Advantages: High development efficiency, can be cross-platform
Disadvantage: Slow running speed

(2) What languages are compiled languages? What are the explanatory languages?

(3) Advantages and disadvantages of Python

Advantages:

Disadvantages:

Cannot be encrypted, cannot be multithreaded,

5. Python type

(1) Types of Python: CPython, Jypython, IronPython, other languages python, pypy


(2) The process of running the first py file:

Python3:python File path Carriage return
Python2:python2 File path Carriage return
Python2 and 3 differences: Python2 The default encoding is ASCII, not utf-8.
Workaround: In the first line of the file Plus: #-*-encoding:utf-8-*-
Python3 the default encoding method is Utf-8.

6. Variables

(1) Variable: The intermediate result of some operations is staged into memory for subsequent code invocation.

(2) Naming rules for variables:
1), must have numbers, letters, underscores any combination, and can not be the beginning of the number
2), cannot be a keyword in python
3), variables are descriptive
4), cannot be Chinese

(3) Recommended naming methods:

7. Constants
Constant amount.

such as: π, bir_of_china=1949

8. Comments
Easy for others to understand the code
Single-line Comment: #
Multiline Comment: "" "," "" "," ""

9. User interaction

# Input name = input (' Please enter your name:'= input (' Please enter your age:')  )print(name,age)

(1), wait for input
(2), the content you entered is assigned to the preceding variable.
(3), input out of all the content is str (string).

10. Initial knowledge of data type
Numbers: int 12, 3, 45.

(1) can be +-*/% (take surplus)
How to determine the data type:

print(100,type),print('+ ', type ('100  '))   

String converted to number: Int (str) Condition: STR must be a numeric component
Convert numbers to Strings: str (int)
String: Str,python all quoted in quotation marks are strings.
Strings can be added (stitched), not subtracted, and multiplied by numbers (str*int).
BOOL: Boolean value. True, False

11. Conditional Statement--if

(1) The first kind:

If condition:
Results

Such as:

Print (111) if True:     Print(666)print(777)

(2) The second type:

If condition:

Results

Else

Results

if 4 > 3:    print(' I'll take you to dinner ')  else:    print(' what to eat ')

(3) The Third Kind

If condition:

Results

Elif Conditions:

Results

Else

Results

Num =input ('Please enter the number you guessed:')ifNum ==1:    Print('Smoking together')elifNum ==2:    Print('Drink Together')elifNum ==3:    Print('Eat together')Else: Ptint ('you guessed it wrong ....')

(4) nesting

#NestingName= input ('Please enter your first name:') Age= Input ('Please enter your age:') ifName = ='Little Two':ifAge = =' -':        Print(666)    Else:Print(333)Else:Print('wrong.')

12. While loop

Format:
While condition:

Loop body (content)

(1) Infinite loop

Count=1 while True:    Print (count)

(2) terminate the cycle: change the condition so that it is not established.

1) Flag bit

# flag Bit  while flag:     Print (count)     = count+1    if count >:    = False

2) Second type: Set the loop termination condition

Count = 1 while Count <=:print= count + 1

3) Third: Keywords: break, continue

# BreakPrint(' One') Whlie True:Print('222')    Print('333')     Break    Print('444')Print('ABC')#ContinuePrint(111) Count=1 whileCount <20:    Print(count)ContinueCount= Count +1

? Python Learning Diary: Day1

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.