python training day1

operation:

# (1) corresponding to the variable name is removed on both sides of the space values 
name = "Alex" 
Print (name.strip ()) 
# beginning (2) determines whether the value corresponding to the variable name to "al", and outputs the result 
# case It is a space for the opening 
Print (name.startswith ( "Al")) 
# (. 3) determines whether the value corresponding to the variable name ends in "x", and outputs the result 
Print (name.endswith ( "X-")) 
# (. 4 ) the value of the variable name corresponding to the "1" is replaced by "p", and outputs the result 
name = name.replace ( "L", "P") 
Print (name) 
# (. 5) corresponding to the value of the variable name in accordance with "1" is divided, and outputs the result 
List = name.split ( 'L') 
Print (List) 
List1 = name.split ( 'P') 
Print (List1) 
# (. 6) corresponding to the name of the variable value becomes capital, and output 
Print (name.upper ()) 
# (. 7) corresponding to the name of the variable value becomes lower case, and the output 
print (name.Lower ()) 
# (. 8) make the output value of the name variable corresponding to the second character 
Print (name [2]) 
# (. 9) Please output name variable corresponding to the first three characters of the value 
print (name [0: 4 ]) 
# (10) Please output name after a variable value corresponding to the two characters
print (name [2: 4] ) 
index # (11) make an output value corresponding to the variable name "e" of the location of 
Print (name.find ( 'E')) 
# (12 is) acquisition sequence, and finally removed a character, as is acquired oldboy oldbo 
Print (name [0: len (name) -1])

to sum up:

Digital Type # 

# integer int 
# 100 = # Number int (100) 
# number2 = int (100) 
# Print (Number) 
# Print (number2) 


# float a float 
# # a float SAL = 15.0 (15.0) 
# = SAL2 a float (15.0) 
# Print (SAL) 
# Print (SAL2) 


# type string 
# name = 'Tank' 
# = NAME2 "Tank" 
# Content = '' ' 
# 1r1r1r 
# 21r12r1 
# r12r 
# 12r1r21 
# r12r1r2 
# 12r1r 
#' '' 
# 
# Print (name, NAME2, Content) 

# Python strings may be added, multiplied 
# Print ( 'Tank' *. 5) 
# Print ( 'Tank' + 'Jam') 
# Print ( 'Tank', 'Jam') 


# list type 
# [] brackets separated by commas, can be stored a plurality of different types of values.
# List1 = [ 'Zhang Man-Man', 'tank', 'Tu Yi Lei',. 11, 1.0, [ 'Jason', 200 is]] 
# Print (List1 [0]) 
# Print (List1 [. 5] [0]) 

# dictionary type 
# in the {} are separated by commas, can be stored a plurality of values, each value key: value stored in the form 
# memory 
# dict1 = { 'name': "tank", "age": 18} # name = { "Tank", "Age"} = 18 is 

# take 
# Print (dict1 [ "name"]) 


# boolean 
# True or False 
# Print (10 == 10) True # 
# Print (== 10. 11) False # 

# Note: All data types Boolean own, 0, None, are empty False 
# 0 IF: 
# Print ( '111') 
# 
# None IF: 
# Print ( '111') 
# 
# IF []: 
Print # ( '111') 
# 
# the else:
Print # ( '222') 



# format output 
# to be replaced once the string type output
# Placeholder% s,% d may be replaced with a digital type 
# number = input ( 'Enter:') 
# = str1 '' ' 
# Dear User, your credit balance membered% s. 
# '' '% Number 
# 
# Print (str1) 


# for cycle 
# List1 = [. 1, 2,. 3,. 4,. 5] 
# for Line in List1: 
# Print (Line) 

# for Line in Range (. 1, 10) : 
# Print (Line) 

# dict1 = { 'name': "Tank", "Age":} 18 is 
# Key in dict1 for: 
# Print (Key) 
# Print (dict1 [Key])

Copy the code
# '' ' 
# Str1 =' XXX My name IS, IS 18 is My Age ' 
# # eliminate spaces around Strip 
# Print (str1) 
# Print (str1.strip ()) 
# # segmentation Split 
# str1.split List2 = ( '') 
# Print (List2) 
# str2 = 'My name IS XXX, My Age IS 18 is' 
# for Line in str2: 
# Print (Line, End = "") 
# STR6 = 'My name in Tank' 
# Print ( str6.lower ()) 
# Print (str6.upper ()) # Lower upper uppercase to lowercase 
# print (str6.startswith ( 'my' )) #startswith determining determines endswith front rear 
# print (str6.startswith ( 'My' ) ) 
# Print (str6.endswith ( 'Tank')) 
# #fomat three kinds of play 
# STR7 = 'My name in {}, {} My Age IS' 
# STR7 = str7.format ( 'Tank',18)
# print(str7)
#
= STR7 # 'My name in {}. 1, 2} {My Age IS' 
# STR7 = str7.format ( 'Tank', 18,111) 
# Print (STR7) 
# 
# STR7 = 'My name in {name}, My Age Age} {iS ' 
# STR7 = str7.format (name =' Tank ', Age = 18 is) 
# Print (STR7) 
#' '' 
# # of the Join list according to some data identifying a string type to be spliced splicing 
name = # 'Tank' 
# Age = '20 ' 
# Print (': 'the Join ([name, Age]).) 
# #replace 
# Str8 =' new new Old ' 
# Str8 = str8.replace (' Old ',' new new ') 
# Print (Str8) 
# #isdigit numeric string is determined whether 
# ID = input (' enter ') 
# Print (ID) 
# Print (ID.isdigit ()) 
List1 = [' Tank ', 18 is, 'womale', 3.0,9]
print(list1[4])
print(list1[-2])


# '''
Str1 = # 'My name XXX IS, IS 18 is My Age'
# str7='my name in {1},my age is{2}'
# # Eliminate spaces around Strip 
# Print (str1) 
# Print (str1.strip ()) 
# # segmentation Split 
# List2 = str1.split ( '') 
# Print (List2) 
# = str2 'My name IS XXX, My IS 18 is Age ' 
# for Line in str2: 
# Print (Line, End = "") 
# STR6 =' My name in Tank ' 
# Print (str6.lower ()) 
# Print (str6.upper ()) # Lower lowercase upper uppercase 
# print (str6.startswith ( 'my' )) #startswith determining determines rear front endswith 
# Print (str6.startswith ( 'My')) 
# Print (str6.endswith ( 'Tank')) 
# #fomat three kinds play 
# STR7 = 'My name in {}, {} My Age IS' 
# STR7 = str7.format ( 'Tank', 18 is) 
# Print (STR7) 
# 
# STR7 = str7.format ( 'Tank', 18 is,111)
# print(str7)
#
= STR7 # 'in My name {name}, {My Age Age IS}' 
# STR7 = str7.format (name = 'Tank', Age = 18 is) 
# Print (STR7) 
# '' ' 
# # of the Join list according to some data identifying a string type to be spliced splicing 
# name = 'Tank' 
# Age = '20 ' 
# Print (': '. the Join ([name, Age])) 
# #replace 
# Str8 =' new new Old ' 
# Str8 = str8.replace (' Old ',' new new ') 
# Print (Str8) 
# #isdigit numeric string is determined whether 
# ID = input (' enter ') 
# Print (ID) 
# Print (ID. isdigit ()) 
List1 = [ 'Tank', 18 is, 'womale', 3.0,9] 
Print (List1 [. 4]) 
Print (List1 [-2]) 
Print (List1 [. 1:. 5: 2]) 

Print (len (List1)) 
# append the append () 
list1.append ( 'sjkd' 
Print (list1.pop ())
print(list1)
# Delete pop () default last -1
Print (list1.pop (0)) 
Print (List1) 
List1. 
# cycles

Guess you like

Origin www.cnblogs.com/wangtianen/p/11006783.html