python learning the next day - and a string formatted output

# String 
# String Value: String name [index] can only take a single value
# n access sequence, starting from 0
str1 = "Hello World"
Print (str1 [. 3]) # Output "l"

Reverse Order Access # , starting from -1
print (str1 [-3]) # output "R & lt"

# string operations: +, *
str2 = "!!! Go Go Go"
Print (str1 + str2) # output "hello world go go! ! Go! "
Print (str2 * 2) output #" Go! Go! Go! Go! Go! Go! "

# Analyzing string in, not in member operator
print ( '0' in str1) # output" False "
print ( '0' not in str1 ) # output "True"

# different types of stitching
NUM = 9527
#Print (str2 + NUM) # given
print (str2 + str (num) ) # output "go! go! go! 9527 " str function converts a type

# string sections
# string name [m: n: k] m : where index of the n: index of the end where +1 k: step
print (str1 [3: 7] ) # output "lo w "k default. 1
Print (str1 [. 3: 10: 2]) # outputs" L OL "
Print (str1 [:]) # Output "hello world"


# Formatted output
# first:% d integers% f float% s string
name = "Wang Jin when"
Age = 20
the Math = 84.25
Print ( "% s% d years old this year, mathematics exam% .3f points"% (name, age, math)) # output "when 20-year-old Wang Jin, 84.250 points in math"
#% d can only put an integer;% f can put an integer, you can also put a float;% s may be a laissez-faire a value
# second: format {}
Print ( "{} {} years old this year, the math sub {}" .format (name, age, math )) # output "Wang Jin 20 years old this year, 84.25 math exam points "
Print (" {1} {0} years old this year, the math {2} points ".format (age, name, math )) # output" Wang Jin 20 years old this year, up 84.25 points in math. "

Guess you like

Origin www.cnblogs.com/w-6711/p/11695413.html