python learning (re0) day 1

I. Introduction

Although in the last year it has been a discrete learning to learn and understand Dijkstra's algorithm started learning python, but after only six months on the python has gradually blurred and forgotten knowledge of grammar.

Second, the learning content today

1) Although the decision to start from scratch, but for basic grammar python or have knowledge and understanding, but learning is a refresher course, study this morning, also I think more skilled with python syntax new understanding, such as for slicing the split of usage, previous study, I only used as a segmentation data processing input and output of the string type of split. but in this morning's learning, learned split function is to process the divided spaces as a character according to a standard character, and the segmented data type is no longer but str list (list type)

2)

Today, learning is mainly some basic syntax and data types in python string type (str)
focus python library to learn is to know, to understand the use of functions, many applications are built-in functions that are implemented by in python, for learning and understanding is learning string string-related functions.
you need to know

1.type function

Usage: type function to determine the type of data

test_='abc'
print(type(test_)

 2.strip function

Usage: remove whitespace string

= str1 ' Hello Cheng   ' 
Print (str1)
 # remove the clear space 
Print (str1.strip ())
 # remove the spaces left 
Print (str1.lstrip ())
 # remove the right box 
Print (str1.rstrip ())

3.lowper and upper functions
usage: case conversion

= str1 ' Hello Cheng ' 
# converted to lower 
Print (str1.lower ())
 # uppercase 
Print (str1.upper ())

4.startswith, endswith function

Usage: determining the value of the beginning or end of the string are equal, instead of returning the return True Flase

= str1 ' Hello Cheng ' 
# determined character is equal to the beginning str1 Hello 
Print (str1.startswith ( ' Hello ' )) # True 
# determines whether the end of characters equal str1 Cheng 
 Print (str1.endswith ( ' Cheng ' )) # True

5.format function

Usage: formatted output

# The format (output format) of the three kinds of play 
str1 = ' My name IS% S, S% Age My! ' % ( ' Cheng ' , 20 is )
 Print (str1)
 # way: the sequence is formatted according to the position 
Print ( ' ! My name IS {}, {} My Age ' .format ( ' Cheng ' , 20 is )) 

# Second way: The index format 
Print ( ' ! My name IS {0}, Age {My}. 1 ' .format ( ' Cheng ' , 18 is )) 

# three ways: by name format 
Print ( 'my name is {name}, my age {age}!'.format(age=18, name='cheng'))

6.split function

Usage: split string. Slicing string specified by delimiters and returns the string list (list) divided

test_='a b c'
print(test_.split())

7.join function

Usage: string concatenation

# The Join string concatenation 
# error, only the strings together 
Print ( '  ' .join ([ ' Cheng ' , 18 is ]))
 # The spaces, each of the string in the list is spliced 
Print ( '  ' .join ( [ ' Cheng ' , ' 18 is ' , ' from GZ ' ]))
 # the _, the list for each string of splicing 
Print ( ' _ ' .join ([ ' Cheng ' , ' 18 is ' , 'from GZ']))

8.replace function

Usage: string replacement

# Replace: string replacement 
str1 = ' My name Cheng IS, IS 20 is My Age! ' 
Print (str1) 
str2 = str1.replace ( ' Cheng ' , ' Qian ' )
 Print (str2)

9.isdight function

Usage: string to determine whether the numbers

INPUT = Choice ( ' select [0, 1, 2]: ' ) 
determines whether the user input selection of a digital 
Print (choice.isdigit ())

Third, the summary

Today it is the third time I came into contact with the new python, in sophomore year when Discrete Mathematics in order to achieve Dijkstra algorithm, independent study of the python, but just learn to understand, is not the system of nature. The second secondary learning opportunities is to facilitate data structure algorithms in the second semester of my sophomore year, began to re-learn, finally encountered some bottlenecks in pta platform, written in python code can not pass a test last point, because the last big test is a test point data for the python language, requires a lot of memory, but in pta to memory is relatively small, often have problems beyond memory. this makes me late in learning, gradually abandoned the use of python data structure to complete the algorithm. the third is the beginning of today's cognitive practice, this opportunity so I began to be able to get the system to review and re-learning python language.

Fourth, work

# Homework 
# front drive author_1704011044 
# python_study_day01_homework 
name = ' a1eX ' 
# Print (type (name)) 
# Ql removed name spaces on both sides of the value corresponding to the variable, and outputs the processing result 
Print (name.strip ())
 # Q2 Analyzing name whether the value of the corresponding variable begins with "a1", and outputs the result 
Print (name.startswith ( " A1 " ))
 # Q3 is determined whether a value corresponding to the variable name "X" at the end, and outputs the result 
Print (name.endswith ( " X- ' ))
 # Q4 corresponding to the variable name value of "1" is replaced by "p", and outputs the result 
Print (name.split ( ' 1 ' ))
 #Q5 corresponding to the variable name value in accordance with "1" is divided, and outputs the result 
NEW_NAME = name.replace ( ' 1 ' , ' P ' )
 Print (NEW_NAME)
 # Q6 are the name of the corresponding variable value becomes capital, and outputs the result 
Print ( name.upper ())
 # Q7 variable name corresponding to the value becomes lower case, and outputs the result 
Print (name.lower ())
 # . 8 outputs a second request corresponding to the variable name character value 
Print (name [2 ])
 # 9 Please first three characters of the output value corresponding to the variable name 
Print (name [0:. 3 ])
 # 10 corresponding to the variable name requested output value after two characters 
Print (name [-2 :])
 # Q11 output name please corresponding to the value of the variable "e" where the position of the index? 
Print (name.find ( ' E' ))
 # Q12 acquisition sequences, removing the last - a character 
Print (name [: -. 1])

 

Guess you like

Origin www.cnblogs.com/pystrade/p/11076877.html