Python basic syntax (3): python basic syntax
Define Variables
In Python, it is very easy to define a variable. In Python, the definition does not need to end with a semicolon. For example:
a = 10b = 3print(a*b)
Judgment statement
The if judgment Statement of Pyhon is composed of if, elif, and else, and each judgment is composed of: end. Python judgment is also very simple.
# Coding = utf-8fenshu = 90if fenshu> = 90: print ("excellent") elif fenshu> = 75: print ("excellent") elif fenshu> = 60: print ("pass") else: print ("fail ")
# Coding = UTF-8 indicates that the compiling language of pycharm is UTF-8.
Each print must be indented.
Loop
# coding=utf-8for i in range(0,100) : print (i)
In python, direct String concatenation of numeric values is not supported. If you want to splice data, you need to use the. format index, starting from 0 in {}. For example:
# Coding = utf-8for I in range (0,100): print ("serial number {0}, {1}". format (I, "Hello, Python "))
Define functions
Define functions in python and use def to define them. You can define parameters or define non-parameters.
# coding=utf-8def a() : print("Hello,Python")def b(c,d): if c>d : return c if c<d : return da()print(b(10,11))