Python Learning notes (i)

Source: Internet
Author: User

Note: Two types of # or "" "" "" "or" "

#coding =utf-8 (English)

--------------------------------------------------
Variables: Declaration and definition without first declaring, assigning values
Like what:
Data_i = 1
str = ' Hello ' #字符串可用 ' or ' "
List = [1,2,[1,2], ' 1321 ']

List: An extension of an array of C languages. The element can be a normal data type or a list or other data type.
List = [1,2,[1,2], ' 1321 ']
Commonly used functions are: Append () Remove ()
--------------------------------------------------
Statements and statement blocks
No ";", for example: print ("-----------") after each statement
Use indentation to represent a block of statements, rather than a common curly brace {}
For example (statement block):
Cave_numbers = List (range (0,20))
Unvisited_caves = List (range (0,20))
Visited_caves = []
Visit_cave (0)
--------------------------------------------------
If statement
If condition:
Body
Else
Body

While statement
While condition:
Body

For statement
For I in ListName:
Body

Import usage
From random import choice
Import Random
--------------------------------------------------
Function
def functionname (Parameter1name, Parameter2name,...):
function body
return something or not
For example:
def setup_caves (cave_numbers):
"" "creat the starting list of caves" ""
Caves = []
For I in Cave_numbers:
Caves.append ([])
Return caves
--------------------------------------------------
Input and output
Print (1, end= '/t ') (or in "You can put everything)
Input (' > ') (or in ' can put everything)

Functions encountered:
Randoms = List (range) #0-19
random_i = Choice (random) #在列表中随机的选择一个元素

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.