This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Introduction | |
| # Day 1 - 30DaysOfPython Challenge | |
| print(2 + 3) # addition(+) | |
| print(3 - 1) # subtraction(-) | |
| print(2 * 3) # multiplication(*) | |
| print(3 / 2) # division(/) | |
| print(3 ** 2) # exponential(**) | |
| print(3 % 2) # modulus(%) | |
| print(3 // 2) # Floor division operator(//) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Casting(转换):将一种数据类型转换为另一种数据类型 | |
| # int to float | |
| num_int = 10 | |
| print('num_int:', num_int) # 10 | |
| num_float = float(num_int) | |
| print('num_float:', num_float) # 10.0 | |
| # float to int | |
| gravity = 9.81 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Arithmetic Operators in Python | |
| # Integers | |
| print('Division without remainder', 7 // 2) # Gives without floating number or without the remainder | |
| print('Modulus', 3 % 2) # Gives the remainder | |
| print('Exponentiation:', 3 ** 2) # it mean 3^2 | |
| print('Mutiplying complex numbers:', (1+1j) * (1-1j)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The most common escape characters: | |
| # \n: new line | |
| # \t: Tab (means 8 spaces) | |
| # \\: Back slash (反斜杠,slash:斜杠) | |
| # \': Single quote (') | |
| # \": Double quote (") | |
| print('I hope everyone is enjoying the Python Challenge.\nAre you ?') # \n: line break(换行符) | |
| print('Days\tTopics\tExercises') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1 | |
| # method 1 | |
| lst = [] | |
| # method 2 | |
| lst = list() | |
| # 2 | |
| lst = ['Beijing', 'Shanghai', 'Guangzhou', 'Shenzhen', 'Hangzhou'] | |
| # 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1 | |
| # method 1 | |
| empty_tuple = () | |
| print(empty_tuple) | |
| # method 2 | |
| empty_tuple = tuple() | |
| print(empty_tuple) | |
| # 2 & 3 | |
| sisters = ('Alice', 'Cici') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # sets | |
| it_companies = {'Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'} | |
| A = {19, 22, 24, 20, 25, 26} | |
| B = {19, 22, 20, 25, 26, 24, 28, 27} | |
| age = [22, 19, 24, 25, 26, 24, 25, 24] | |
| # 1 | |
| print(len(it_companies)) | |
| # 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A dictionary is a collection of unordered, modifiable(mutable) paired (key: value) data type. | |
| # Creating a Dictionary | |
| # To create a dictionary we use curly brackets, {}. | |
| # syntax | |
| empty_dict = {} | |
| # Dictionary with data values | |
| dct = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3', 'key4': 'value4'} | |
| person = { | |
| 'first_name': 'Fangyu', | |
| 'last_name': 'Qu', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If Condition | |
| # In python and other programming languages, | |
| # the key word if we use to check if a condition is true and to execute the block code. | |
| # Remember the indentation (缩进) after the colon (冒号). | |
| # syntax | |
| # if condition: | |
| # this part of code runs for true conditions | |
| a = 3 | |
| if a > 0: | |
| print('A is a positive number') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1 | |
| n = 0 | |
| while n <= 10: | |
| print(n) | |
| n += 1 | |
| # 2 | |
| print() | |
| n = 10 | |
| while n >= 0: |
OlderNewer