Follow the code agronomy python 1. First knowledge of Python

Source: Internet
Author: User

This time the company useful Python needs, so to learn some Python knowledge, if the company needs to learn a file read and write, Excel read and write, make an automated Android packaging can be, you have always wanted to do a self-favorite independent game, Server primary Kbengine, intends to learn python, their own independent game dream, in case the implementation of it! Starting today from 0 to learn python, so small white can also easily read!

#Author:jason Zhang" "in Python, immutable object types, such as numbers, characters, tuples, and so on, belong to the value-passing dictionary, and mutable objects such as lists are referred to as the type of value-passing below." "First_var="Hello World"Second_var=First_varPrint("First_var:", First_var) First_var="Hello"Print("Secon_ver:", Second_var)

Comment: Single line comment ' # ' in Python, as above "# Anthor:jason Zhang", multiline comment "" "" "" "," "", three single quotes or three double quotation marks beginning and ending

Constants: The constants are represented in uppercase letters in Python, but can still be modified

Process Control Syntax:

#Author:jason Zhang" "If condition control: Codeelif condition control: Codeelse:code" "#process-controlled guessing numbers gameTarget_num = 10Guess_num= Int (Input ("Guess a num:"))ifGuess_num = =Target_num:Print("You win")elifGuess_num <Target_num:Print("Think Bigger")Else:    Print("Think Smaller")

In Python is the scope of the control code by indentation, Python is a strongly typed language, and the type is converted using the target type (primitive type) when converting the type

Syntax for a looping statement:

#Author:jason Zhang#While syntaxTarget_num = 10Index=0 whileIndex < 10: Guess_num= Int (Input ("Guess a num:"))    ifGuess_num = =Target_num:Print("You win")         Break    elifGuess_num <Target_num:Print("Think Bigger")    Else:        Print("Think Smaller") Index+ = 1Else:    Print("youhave Trid too many times!!")

Python while and most languages do not pass, while can be followed with else: when the index < 10 control statement does not immediately jump out of the loop to execute the ELSE: statement other times do not execute

#Author:jason ZhangGuess_target_num = 10 forIinchRange (3): Guess_num= Int (Input ("Guess Num:"))    ifGuess_num = =Guess_target_num:Print("Guess Success!")         Break    Else:        Print("Guess failed!!")#the For statement's else is normal for complete execution break does not executeElse:    Print("You try too many times!! Game over!")#range (start value, final value, step size) forIinchRange (0,10,1):    ifI < 5:        Continue    Else:        Print("Continue Test:"I

The syntax for a for statement is the same as the while statement, which is executed when the actual condition is not true.

Follow the code agronomy python 1. First knowledge of Python

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.