You are on page 1of 10

What is Python Programming Language?

• Python is a popular programming language. It was


created by Guido van Rossum, and released in 1991.
• It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
• Syntax is about the structure or the grammar of the language. 
• Semantics is about the meaning of the sentence. It answers the
questions: is this sentence valid? If so, what does the sentence
mean? 
Syntax
>>> print("Hello, World!")
Hello, World!

>>> if 5 > 2:
   print("Five is greater than two!")
Syntax continue
>>> print("This line will be printed.")

>>> x = 1
if x == 1:
# this is comment example indented if "x is = 1")four spaces
print("x is equals to one")

>>> print("Goodbye, World!")

>>> print('Enter your name:')


x = input()
print('Hello, ' + x)

# Same as
>>> x = input("Enter your name:")
print("Hello, " + x)
Python Conditions and If statements

• Python supports the usual logical conditions from


mathematics:
• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
• These conditions can be used in several ways, most
commonly in "if statements" and loops.
• An "if statement" is written by using the if keyword.
If statement example
• Example
• If statement:
• a = 33
b = 200
if b > a:
  print("b is greater than a")
Example of if condition
• if 5 > 2:
  print(“5 is greater than 2")
• # let the two numbers store in a variable a and
b
• #compare the two numbers, if a is greater
than b then print “a is greater than b” else
print “b is greater than a”
• Let the two variables entered and compare.
The same process from the previous slide.
Solution 1
x=5
y=21
if x > y:
print("x is greater than y!")
else:
print("y is greater than x!")
Solution 2
x=input("enter 1st number: ")
y=input("enter 2nd number: ")
if x > y:
print("1st is greater than 2nd!")
else:
print("2nd is greater than 1st!")

You might also like