Python basic syntax (3): python basic syntax

Source: Internet
Author: User

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))

 

Related Article

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.