Kita sudah mempelajari module 1 (Up Grade Live: Python Beginner - Module 1 - Dave & Alison 01) dan video 1&2 dari Dave Gray.
Sekarang kita akan mempelajari Module 2 dan video 3 & 4 (Python Operators for Beginners | Python tutorial - YouTube) dari Dave Gray).
Anda juga bisa belajar dari sumber ini: freeCodeCamp.org - YouTube. Sebagai tambahan.
Module 2, Chapter 1
First Program
In Python, which of these functions will display the phrase "Hello John" to the user? Choose one.
* print("Hello John")
-------------------------------------
Module 2, Chapter 2
Variables ---> somethings can change
What term refers to a reserved memory location to store value(s) and serves as a reference or pointer to the value(s) stored in it? Choose one.
- Variables
---------------------------------------
Module 2, Chapter 3: The Basics of Python | Types of Data | Alison
Data type:
Integer: 0, 1, 2, -1, 12, 34
12.0 ...> not integer, but float
12.0 ...> anything with decimal is not integer.
Float ...> Anything with decimal: 12.0, 3.14, 23.1, -3.68
String ...> collection of different characters
"12" ...> string, not integer.
"name", 'John',
Boolean ...> values, either True or False
Which of these are data types available in Python? Choose three.
- floats
- strings
- integers
-----------------------------------------
Module 2, Chapter 4
using variables: The Basics of Python | Using Variables | Alison
Create variable:
True or False: To create a variable, you just declare it by assigning a value to it.
- True
-------------------------------------------------
Module 2, Chapter 5
number = "12"
print(type(number))
Run Python File:
<class 'str'>
Note: 12..> integer, but "12"..>String
Change from String to Integer
number = "12"
print(type(number))
number = int(number)
print(type(number))
Run Python File:
<class 'str'>
<class 'int'>
Change from string to integer to float
number = "12"
print(type(number))
number = int(number)
print(type(number))
number = float(number)
print(type(number),number)
Run Python File:
<class 'str'>
<class 'int'>
<class 'float'> 12.0
A representation such as "12" with the quotation marks in Python will be classified under what kind of data? Choose one.
- String
-------------------------------------------
Module 2, Chapter 6
User Input
age = input('enter your age : ')
print('you are ' + str(age) + ' years old')
Run Python File:
enter your age : 59
you are 59 years old
name = input('enter your name : ')
print('Hello, ' + name)
Run Python File:
enter your name : Atun
Hello, Atun
True or False: The Input() function is the one used to receive data from users.
- True
------------------------------------------------------------------
Module 2, Chapter 7
a = 9
b = 2
a/b = 4.5
a//b = 4
Note: // is "floor division": 3//1.6 = 1.88 = 1
a**b = 9**2 = 81
% = module = mod...> reminder after division.
9%2 = 4+1 .....> reminder = 1
8%2 = 0 ...> reminder = 0
print('welcome to super simple calculator')
a = float(input('enter first number : '))
b = float(input('enter second number : '))
print('your answer is', a + b)
Run Python File:
enter first number : 1.5
enter second number : 19.5
your answer is 21.0
In Python calculations when a = 5, and b = 2. What value will a//b return? Choose one.
- answer: 2
The followings are the key points from this module:
Functions are predefined procedures in a programming language where you can pass certain arguments to them and they will carry out the instructions from the arguments.
'.py' is the extension that all Python files carry.
Variables are data holders that you can use as containers to save data which you can refer to later in programing instead of actually writing such specific data several times.
The different types of data mentioned in the module include:
Integers - These are whole numbers that don't carry decimals. e.g. 1, 6, 52, 105, etc.
Floats - These are the numbers with decimals. e.g. 12.0, 20.351, 15.105112, 2.05, etc.
Strings - These are collections of any and/or different characters. e.g. 0, 52, ABC, *, &, #, John, etc.
Boolean - This is a value that is either true or false.
=======================================
=======================================
Dave Gray : Python for Beginner
3/24: Python Operators: Python Operators for Beginners | Python tutorial - YouTube
We start with assignment operators
Di new terminal> python3, maka akan muncul: >>> ....> sign of REPL
>>> meaning = 42
>>> meaning
42
>>> 24%5
4 ...> reminder : 24%5 = 4+4
>>> 24%3
0 ...> reminder: 24%3 = 8 + 0
>>> 2 ** 3 ---> two power 3
8
sign equal to: ==
42 == 42
True
sign not equal to: !=
42 !=42
False
42 != 43
True
Value of meaning = 42
meaning = 42
print('')
if meaning > 10:
print('Right on!')
else:
print('Not today!')
Run Python File:
Right on!
Changed value of meaning to be 8
meaning = 8
print('')
if meaning > 10:
print('Right on!')
else:
print('Not today!')
Run Python File:
Not today!
-------------------------------------------------------------------
Dave Gray : Python for Beginner
4/24: Data type: Python Data Types for Beginners | Python tutorial - YouTube
We start with data type:
# literal assignment
first = "Dave"
last = "Gray"
print(type(first))
Run Python File:
<class 'str'>
# Escaping Special Characters
sentence = 'I\'m back at work!\tHey!\n\nwhere\'s this at\\located?'
print(sentence)
Run Python File:
I'm back at work! Hey!
where's this at\located?
# String Methods
print(first)
print(first.lower())
print(first.upper())
print(first)
Run Python File:
Dave
dave
DAVE
Dave
# build a menu
title = "menu".upper()
print(title.center(20, "="))
Run Python File:
========MENU========
Next Lesson 5/24 : Python User Input & Control Flow | Python tutorial - YouTube
JJJJJJJ
No comments:
Post a Comment