Last active
July 30, 2019 01:26
-
-
Save sakukode/623bcd2506e2c16f1346569ee2f2abff to your computer and use it in GitHub Desktop.
Fundamental Python
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
| # python doesn't know the data type | |
| # variable naming cannot use space or minus(-) characters | |
| # print text using cmd "print" | |
| print('Hello World') | |
| # print variable using cmd "print" | |
| message = "Hello Python" | |
| print(message) | |
| # Logical If and else | |
| age = 17 | |
| if age <= 17: | |
| print("You can't drive a car") | |
| else: | |
| print("Yes, you can") | |
| exam = 70 | |
| if exam >= 80: | |
| print("Yeay, you've got A") | |
| elif exam >= 60 | |
| print("Good, you've got B" | |
| else: | |
| print("Sorry, you need study harder") | |
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
| # Using Loop with For and While | |
| # print variable name 3 times "For" | |
| name = "Rizqi" | |
| for i in range(0,3): | |
| print(name) | |
| # Code inside block while,it will always excuted if condition while is true | |
| fuel = 80 | |
| while fuel > 0: | |
| print("Car can still run, fuel %s remaining" % fuel) | |
| fuel = fuel - 10 | |
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
| # LIST | |
| # using square bracket to definition | |
| students = ["Andi", "Bunga", "Citra"] | |
| print(students) | |
| # add new student | |
| students.append("Dony") | |
| # print all students | |
| for student in students: | |
| print(student) | |
| # DICTIONARY | |
| # using curly bracket to definition | |
| people = {} | |
| # add attributes | |
| people['name'] = "Rizqi" | |
| people['age'] = 30 | |
| people['sex'] = "male" | |
| print(people) | |
| # add other attribute | |
| people['address'] = "Pekalongan" | |
| print(people) | |
| # convert data dict to json | |
| import json | |
| print(json.dumps(people)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment