< Tanzhou Education >-python Learning notes @ Job 1

Source: Internet
Author: User

Homework:

1. Define each type of value spoken, sequence type

Numeric type:

Integral type: int
Character Type: float
String: str
Boolean type: BOOL

Sequence Type:

List: Ordered, variable, element type no fixed requirements
LST = [+ +]

Ganso: Orderly, cannot be changed, no fixed requirement for element type
Tuple_list = (1,2,3,4,5)

Dictionary: Unordered, key-value pairs combination, facilitate retrieval
Dict = {' username ': ' Stone ', ' passwd ': ' HelloWorld '}

Collection: unordered, element type no fixed requirement
Set_list = {1,2,3,4}

2.python inside how to comment code?

Method 1: Add ' # ' to the beginning of the code
# This is a example
# #方法2: Triple Quote Wrap comment section

Method 2: Three-quote Comment

‘‘‘
This is the example
This is three example
‘‘‘

Extension section: Comment Code application, construction document string # Document string, to explain the function function of the Help document
#文档的使用要求: Must be in the first line of the function,
#查看方式: Use the Help view function in interactive mode, function.__doc__ view in text mode


Def inputxy ():
"This is a documents file"
print ' Hello Stone '

Inputxy ()

Print inputxy.__doc__

# #3. Describe the naming rules for variables


‘‘‘
Python variables are mainly composed of letters, numbers, underscores, and C language, the number can not be at the beginning of the variable, in order to facilitate the identification of distinguishing, the definition of variables is best easy to understand, with the actual match for easy understanding, variable
The name is better followed by the hump nomenclature.

‘‘‘

4. There is a list of li= [' A ', ' B ', ' C ', ' d ', ' e '], using the knowledge of the first lesson, to reverse the list, and then use a number of methods # to remove the second element

# You cannot use the list method reverse and the function reversed, the more methods the better.

Li = [' A ', ' B ', ' C ', ' d ', ' e ']
# #方法1
Li = li[::-1] # reverse sectioning
Print Li

#方法2:
Li = [' A ', ' B ', ' C ', ' d ', ' e ']
Li.reverse ()
Print Li

#方法3:
Li = [' A ', ' B ', ' C ', ' d ', ' e ']
L = Reversed (LI)
New_list = []
For X in L:
# print X,
New_list.append (x)
Print New_list

# #print List (Reversed (LI))


#方法四:
Li = [' A ', ' B ', ' C ', ' d ', ' e ']
Print sorted (Li,reverse = True)

5. There is a time form (20180206), by dividing and taking the remainder, to get the corresponding day, month, year. Please use the code to complete. #时间字符串处理

Date = ' 20180206 '

# 1 Using string slicing operations
Year = Date[0:4]
month = Date[4:6]
Day = Date[6:8]
Print Year,month,day


# the 2 # # # using the addition of & redundancy evaluation
year = Int (date)/10000
Month = (int (date)/100)%100
day = Int (date)%100
Print year
Print Month
Print Day


#way 3 evaluation using time arrays
Import time
Time_struct = time.strptime (date, '%y%m%d ')
years = Time.strftime ('%Y ', time_struct)
months = Time.strftime ('%m ', time_struct)
Days = Time.strftime ('%d ', time_struct)
Print Years,months,days,

6 a circle with a radius of 10 to find its area (the Math module has π) Import Math

PI = Math.PI
R = 10
s = pi*r*r
print ' area is: ', '%.6s '%s

< Tanzhou Education >-python Learning notes @ Job 1

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.