pytnon study day-1

Beginner python

 

The first code

print('hello world!')

 

What is a variable?

Variables: the amount of change

Variable value: will produce a memory address in memory

Variable name: variable bindings for

name='tank' 
print(name)  #tank

 

python language naming convention:

1. To start with an English letter or an underscore naming

2, can not start with a number name

3, the keyword can not be named

 

Defined variable names a bad way

1, not to Chinese name

2, the variable name is too long

3, variable terms do not convey

 

Three characteristics defined variables

ID # is used to indicate a unique value of a variable memory address in memory 
type # type variable value 
value # value of the variable

 

Users interact with a program
    input:
        the INPUT ()
    Output:
        Print ()
 
Formatted output
    Dear customer, hello! Your month deducted 99 yuan bill, left 0.
    # By some placeholder character for a location in the replacement string.
    Placeholder:
        % S: can replace any type of
        % d: can be replaced by a digital type
    Example:
        Dear customer, hello! Your phone bill this month deducted yuan% s,% d remaining yuan.
 
Basic data types
    1. Digital Type:
        Integer: int
        Float: float
    2. String type
        role: name, sex, nationality, address and other descriptive information
        Definition: single quotation marks \ double quotes \ three marks, a string of characters
            name = 'tank'
        The priority control operations:
            1, according to the index value (Forward + Reverse take take): can only take
            2, sections (care regardless of the end, step)
            3, the length len
            . 4, the members in operation in and Not
            . 5, shift In addition to the blank Strip
            . 6, segmentation Split
            . 7, loop
# By index value
# Take forward
str1 = 'hello world!'
print(str1[0])
print(str1[9])

# Reverse take
print(str1[-2])

Slice # (care regardless of tail)
print(str1[0:5])

# Steps
print(str1[0:11])
print(str1[0:11:2])

# Length len
print (referred to as (str1))

# Members in and not in operation
print('h' in str1)
print('h' not in str1)

# Remove blank strip
# Removes spaces left and right sides of the string
str1 = '   hello world!'
print(str1)
str1 = '   hello world   '
print(str1)
print(str1.strip())

# Removal of the specified string
str2 = '!world'
print(str2.strip('!'))

# Segmentation split
str1 = 'hello world!'
# Space be segmented in accordance str1
# Slicing out value will be stored in [] list
print(str1.split(' '))


#cycle
# Of str1 string traversal, print each character
for line in str1:
    print(line)

# Cycle
       
Need to know:
            . 1, Strip, the lstrip, The rstrip
            2, Lower, Upper
            . 3, startsWith, endsWith
            . 4, the format of the three kinds of games are played
            . 5, Split, rsplit
            . 6, the Join
            . 7, Replace
            . 8, isdigit
# . 1, Strip, the lstrip, The rstrip 
# str1 = 'Hello wuyuefeng' 
# Print (str1) 
# # to remove the clear space 
# Print (str1.strip ()) 
# # remove left spaces 
# Print (str1.lstrip ()) 
# # remove the right space 
# Print (str1.rstrip ())


# 2, Lower, Upper 
# str1 = 'Hello WuYueFeng' 
# # to lower case 
# Print (str1.lower ()) 
# # uppercase 
# Print (str1.upper ())

# . 3, startsWith, endsWith 
# str1 = 'Hello WuYueFeng' 
# # # str1 determined character is equal to the beginning Hello 
# Print (str1.startswith ( 'Hello')) True # 
# # # determines whether the end of characters equal str1 WuYueFeng 
# Print ( str1.endswith ( 'WuYueFeng')) # True
#
# #. 4, the format (output format) three play 
# # str1 = 'My name IS% S, S% Age My!'% ( 'Tank', 18 is) 
# # Print (str1)
#
# # Way: The sequence formatter position 
# Print ( 'My name IS {}, {} Age My!' The format ( 'Tank', 18 is).)
#
# # Second way: The index format 
# Print (. '! My name IS {0}, Age {My}. 1' the format ( 'Tank', 18 is))
#
# # Three ways: by name format 
# Print ( 'IS My name {name}, {My Age Age}!' The format (Age = 18 is, name = 'Tank').)

# 5, Split segmentation


# . 6, the Join string concatenation 
# error, only string concatenation 
# Print ( '' .join ([ 'Tank', 18 is])) 
# # The spaces, each of the string in the list is spliced 
# Print ( '' .join ([ 'Tank', '18 is', 'from GZ'])) 
# # _ according, to list each string splicing 
# Print ( '_'. the Join ([ 'Tank', '18', 'from GZ' ]))

# . 7, Replace: string replacement 
# str1 = 'My name IS WangWei, Age 73 is My!' 
# Print (str1) 
# str2 = str1.replace ( 'WangWei', 'SB') 
# Print (str2)

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

 

 

   

 

 

 

 

Guess you like

Origin www.cnblogs.com/talk-one/p/11076990.html