What is python?
Python is a general-purpose programming language. Created by Guido van Rossum and first released in 1991.
Learning Python is like learning new language. So far I’ve been learn about Boolean, if/elif/else statement, while loop, break statement, continue statement, range function and infinite loop.
What is Boolean?
Boolean is data type that can have values True or False.
Example: “hello” is not “goodbye”
What is if/elif/else statement?
- If statement is the statement which if the condition is true perform the action.
- Elif statement is allow to use more than one if and will choose between if and elif.
- Else is the last condition of if and elif and if everything is wrong will perform the else.
Example:
a = 5
if a % 2 == 0:
print(“Even number”)
elif a % 2 == 1:
print (“Odd number”)
else:
print (“I’m not sure what’s happening”)
What is while loop?
While loop, used when a condition needs to be checked each iteration, or to repeat a block of code forever.
Example:
fruits = [‘banana’, ‘apple’, ‘mango’]
for fruit in fruits:
print ‘Current fruit :’, fruit
What is break statement?
Break statement is the statement that stop the rest of the code.
Example:
fruits = [“apple”, “banana”, “Mango”]
for x in fruits:
print(x)
if x == “banana”:
break
What is continue statement?
Continue statement is the skip a code and continue to the next statement.
Example:
fruits = fruits = [“apple”, “banana”, “Mango”]
for x in fruits:
if x == “banana”:
continue
print(x)
What is range function?
Range function is the range the code in older or limit.
Example:
for x in range(10):
print(x)
What is infinite loop?
Infinite loop is the loop that will never stop.
Example:
i = 1
while i < 6:
print(i)
Note: To Stop infinite loop is add :
Example:
i = 1
while i < 6:
print(i)
i += 1