Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Basic_Python_2

The document provides an overview of basic Python operations including user input, string manipulation, boolean values, lists, and conditional statements. It includes examples of how to perform these operations and quizzes to test understanding. The content is structured in a way to facilitate learning Python programming concepts.

Uploaded by

Akaruku Media
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Basic_Python_2

The document provides an overview of basic Python operations including user input, string manipulation, boolean values, lists, and conditional statements. It includes examples of how to perform these operations and quizzes to test understanding. The content is structured in a way to facilitate learning Python programming concepts.

Uploaded by

Akaruku Media
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Python Operation

Python
Operation,
List &
Condition

Page 01
Content

Python: User Input Python: String


Operation
Slicing string in variables
Python allows for user input. That
means we are able to ask user for
answer or input in any form.

Python: Booleans Python: String


Formatting
The function format().
There are two boolean statement:
True and False

Python: List Python: Conditions


(If...Else)
Variable containing multiple
Using conditions in If Else
values
Statement
Page 02
Python: User Input

Python allows user to input values, and this is how!

Python allows for user input.


That means we are able to ask the user for input as a string.

Example:
name = input("Enter name:")
print("Your name is: " + name)

Page 03
Python: String Operations

Get the character at position 1 (the first character has the position 0)
a = "Hello, World!"
print(a[1])

Get the characters from position 2 to position 5 (not included):


b = "Hello, World!"
print(b[2:5])

The len() function returns the length of a string:


a = "Hello, World!"
print(len(a))

Page 04
Python: String Operations

Merge variable a with variable b into variable c:


a = "Hello"
b = "World"
c=a+b
print(c)

To add a space between them, add a " ":


a = "Hello"
b = "World"
c=a+""+b
print(c)

Page 05
Python: String Formatting

The format() method takes the passed arguments, formats them, and
places them in the string where the placeholders {} are:

age = 36
txt = "My name is John, and I am {}".format(age)
print(txt)

Page 06
Quiz Session

Page 07
Quiz

What is output from this code :

if x = "Indonesia AI"
❖ print(x[2:4])
❖ print(len(x))

Page 08
Python: Booleans

Booleans represent one of two values: True or False.

Example:
print(10 > 9)
print(10 == 9)
print(10 < 9)

a = 10
b=9
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")

Page 09
Python: List

They can contain any type of variable, and they can contain as many variables as you
wish. Lists can also be iterated over in a very simple manner. Here is an example of how
to build a list. For example:

mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
print(mylist[0]) # prints 1
print(mylist[1]) # prints 2
print(mylist[2]) # prints 3

for x in mylist: # prints out 1, 2, 3


print(x)

Page 10
Python: Conditions (If...Else)

Python uses boolean variables to evaluate conditions. The boolean


values True and False are returned when an expression is compared
or evaluated.

Conditions : ==, !=, >, <, >=, <=, and, or , not

a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")

Page 11
Quiz Session

Page 12
Quiz

What is output from this code:

c=3
a=c
b=c+1
if b > a:
print("b is greater than a")
elif c == b:
print("c is same like b")
else :
print('other')

Page 13
Terima Kasih!
Indonesia AI | AI for Everyone, AI for Indonesia
contact@aiforindonesia.org

You might also like