NEW
Font size
WorksheetsKuis Python Lanjutan kelas XII
Total questions: 10
Worksheet time: 8mins
Example:
X=1.0
Y=12.3
Z=-13.4
Diatas adalah contoh dari type data ....
Integer
Long Integer
float
char
String
Example: Vardemo1.py
x=y=z=50
print x
print y
print z
Berapakah hasil (output) dari kode program diatas ...
50
05
50
50
50
50
05
50
100
150
50
50
50
Secara umum, Komentar digunakan dalam bahasa pemrograman untuk mendeskripsikan program atau menyembunyikan beberapa bagian kode dari penerjemah. Komentar dalam Python dapat digunakan untuk menjelaskan kode program apa pun. Komentar juga dapat digunakan untuk menyembunyikan kode. Berikut adalah penulisan Komentar yang SALAH pada python adalah...
# This is single line comment
print "Hello Python"
""" Penulisan Komentar lebih dari satu baris yaitu dengan menggunakan kutip dua 3 kali dan ditutup dengan kutip dua 3 kali juga """
$Komentar dituliskan dengan kode $
print("Hello World") #ini juga komentar
# komentar bisa berisi spesial karakter !@#$%^&\*(),./;'[]\
Example:
A=2+5j
B=-3+4j
C=-6j
Diatas adalah contoh type data ....
Int
Float
Str
Complex
Bool
Example: “datatypesdemo.py”
a=10
b=“Python"
c = 10.5
d=2.14j
print("Data type of Variable a :",type(a))
print("Data type of Variable b :",type(b))
print("Data type of Variable c :",type(c))
print("Data type of Variable d :",type(d))
Dari kode diatas, apakah outputnya ....
Datatype of Variable a : <class ‘a’>
Datatype of Variable b : <class ‘b’>
Datatype of Variable c : <class ‘c’>
Datatype of Variable d : <class ‘d’>
Datatype of Variable a : <class ‘int’>
Datatype of Variable b : <class ‘str’>
Datatype of Variable c : <class ‘float’>
Datatype of Variable d : <class ‘complex’>
TypeData of Variable a : <class ‘int’>
TypeData of Variable b : <class ‘str’>
TypeData of Variable c : <class ‘float’>
TypeData of Variable d : <class ‘complex’>
Datatype of Variable a : <class ‘int’>
Datatype of Variable b : <class ‘int>
Datatype of Variable c : <class ‘int’>
Datatype of Variable d : <class ‘int’>
Datatype of Variable a : <‘int’>
Datatype of Variable b : <‘str’>
Datatype of Variable c : <‘float’>
Datatype of Variable d : <]‘complex’>
eg:
a=20;
b=10
then a % b= .....
0
1
2
3
4
a=24;
b=7
then a // b = .....
0
1
2
3
4
Berikut contoh kode program dari operator Gabungan Assignment Python:
x = 10
x += 5
print('x += 5 :',x)
x = 10
x /= 5
print('x /= 5 :',x)
x = 10
x **= 5
print('x **= 5 :',x)
x = 10
x <<= 2
print('x <<= 2 :',x)
Dari kode-kode diatas, bagaimanakah outputnya .....
x += 5 : 15
x /= 5 : 2.0
x **= 5 : 100000
x <<= 2 : 40
x += 5 : 1
x /= 5 : 2.0
x **= 5 : 30
x <<= 2 : 40
x += 5 : 4
x /= 5 : 2.0
x **= 5 : 100000
x <<= 2 : 40
x += 5 : 50
x /= 5 : 2.0
x **= 5 : 100
x <<= 2 : 40
x += 5 : 1
x /= 5 : 2
x **= 5 : 3
x <<= 2 : 4
Seperti bahasa pemrograman lainnya, pengindeksan string Python dimulai dari 0. Misalnya, string "HELLO" diindeks seperti yang ditunjukkan pada gambar di bawah ini.
str="HELLO"
Untuk str[2], maka output yang akan tampil adalah = ...
H
E
L
L
O
str1 = "Python is a programming language"
str2 = str1.split()
print(str1);print(str2)
Dari kode diatas, bagaimanakah output yang akan tampil ....
Python is a programming language
Python, is, a, programming, language.
Python is a programming language
['Python', 'is', 'a', 'programming', 'language']
Java is a programming language
['Java', 'is', 'a', 'programming', 'language']
Python is a programming language
Python, is, a, programming, language.
