Learning Python(First Day)
Abstract: Basic Operation of Jupyter, Output, Input, Slicing of String, Basic Function and Some Tips
-
Basic Operation of Jupyter
- ctrl+enter
It means that run codes only in this cell. - shift+enter
It means that run codes only in this place and create a new space below this cell. - restart
It is similar to ‘F5’ in Windows. - insert
It indicates that create a new cell above current cell or below current cell.
- ctrl+enter
-
Output
print(" Hello world")
- Input
sentence = input()
4.Slicing of String
sample_string = "I am the best"
print(sample_string[0]) # the first word in the string numbers 0
print(sample_string[1])
print(sample_string[2])
# The words in string can not only be summarized by positive number, but can be also summarized by nagtive number
print(sample_string[-1]) # It equals sample_string[12] in this string
print(sample_string[-5])
#Slicing a substring
print(sample[1:8]) # It means that printing from the second word( represented by '1') to the seventh word ( '8-1 = 7')
print(sample[ :8]) # It means that printing from the beginning word to the seventh word
print(sample[1: ]) # It means that printing form the second word to the end
print(sample[1:8:2]) # It means that printing from the second word to the seventh word with 2 steps
print(sample[1:8:-1]) #It means that reversing the string
#Remember, the number can not exclude the specific range.
- Some basic function
word = sample_string[0]
word.isalpha() # check whether the letter is alpha or not
word.lower() # such as A to a
word.upper() # such as a to A
str_length = len(sample_string) # the length of the string
- Tips
From floating to integer, it will ignore the number behind the dot.