Python basic syntax

Source: Internet
Author: User

----------------------------IV----------------------------

Print function

---------------------------------------------------
Print----Encoding-----Code encoding consistent with file encoding
----------------------------------------------------


PY2: Chinese will error----default ASCII
PY3: No error-----default UTF-8

-----------ASCII code (255) does not include Chinese-----------
-----------UTF-8 (all characters)-------------------
-----------gbk--(Chinese)-----------------------


Py2 >>> convert--------#-*-encoding:utf-8-*-------------------
Py2 >>> convert--------#-*-encoding:gbk-*-------------------

Assigning values to variables

-----------
Assigning values to variables
-----------

Variable name <--msg = '--string----------------an equals sign
2--Digital type
2.34---> Floating point

-----Easy to use multiple times
-----can modify the content to point to

------------------------
Variable name naming rules:
-------------------------

Can only be letters, numbers, underscores
Numbers can not start
Cannot be a keyword inside python

Age=18
Age1=age
Age2=age1
age1=666

Print ("Age,age1,age2")

Data type

-------------------------------------------------------------

------Integer Type-----age=18
------String Type----"Apple"
------Boolean Type-----true--false

type of Operation

---------------------------------------------------------------

------Arithmetic Operations

Numbers: result=1+1-----Subtraction-----

String: result= "abc" *8
result= "abc" + "ACD"

------comparison operation

-Conditional statements

--------------------------------------------------------------

If [condition]:
Age = = Input (")
If [condition]:
Print (")
Else
Print (")


elif [conditions]:
Print (")

Else
Print (")


-------conditions from the top down---------

-------------four spaces to indicate indentation---------


---------------------------------------
Input ()---->>> can only get string
-------------------------------------


Looping statements

-----------------------------------------

---
While [condition]:

Print (1)

While True:----------------dead Loop

Print (2)
Print (3)
Print (4)


Print (5)


------------------------
While:

Break---Jump out of the loop
------------------------


------------------------------
While
Continue-----Jump out of this cycle
-----------------------------------

Python basic syntax

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.