print("Mohan", "Kavin", sep="-------- ", end="!")
%
- Mohan-------- Kavin!
- variable can't do any task, it just remembers name or value
- function is a specific task, function always has parenthesis
- Function is tiny program
- Function might take one or more input
- Function would always produce output
- If function not producing output, we assume it produced None as its output
- 3 arguments
- [start:stop:increment]
[0,1,2,3,4][-1::1] and [0,1,2,3,4][-1]
%
- [4] and 4
- One is list and another is int
>>> [1,2,3,4][::-1]
[4, 3, 2, 1]
%
- 'vnih'
- We should convert string into int using int(string) function
- int("3")
middleIndex = int((len(testString) - 1) / 2)
testString="Kavin"
middleIndex = int((len(testString) - 1) / 2)
print(middleIndex)
%
- 2
>>> for i in range(0,10):
... print(i)
>>> while True:
... print("Kavin")
str1 = input("Please enter a word\sentence: ")
stringVariable = input("Please enter a word\sentence: ")
number = int(stringVariable)
>>> import random
>>> random.randint(10,25)
23
for i in range(1,11):
print(i*2)
2
4
6
8
10
12
14
16
18
20
for table in range(2,5):
for line in range(1,5):
print(table*line)
print("\n")
2
4
6
8
3
6
9
12
4
8
12
16
%
def mid3(testString):
# Check if the number is odd or even
# using the modules operator
if len(testString) % 2 == 1 and len(testString) > 7:
middleIndex = int((len(testString) - 1) / 2)
print(testString[middleIndex - 1])
print(testString[middleIndex])
print(testString[middleIndex + 1])
%
def VerticalPrint():
stringVariable = input("Please enter a word\sentence: ")
print("This input has " + str(len(stringVariable)) + " characters")
for i in range(0, len(stringVariable), 1):
print(stringVariable[i])
%
def ReverseString():
# Reverse print a string
stringVariable = input("Please enter a word: ")
for i in range(len(stringVariable) - 1, -1, -1):
print(stringVariable[i], end="")
%
for i in range(1,11):
print(i)
%
>>> for i in range(1,11):
... print(i*2)
...
%
>>> for i in range(1,11):
... print(" ")
... for count in range(1,i+1):
... print("*", end=" ")
...
""" 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 """ %
def NumPyramid2(rowNum):
for j in range(2, rowNum + 2, 1):
for i in range(1, j, 1):
print(i, end=" ")
print("\r")
if score = 12 ^^, score greater than 15 **, > 5 %_% %
if score > 12:
print("^_^")
elif score > 15:
print("*_*")
elif score > 5:
print("%_%")
else:
print("#_#")
wow
wow
going to get 5
going to get 5
I got 5
%
cookie_count = 0
while True:
cookie_count = cookie_count + 1
if cookie_count > 4:
print("I got 5")
break
elif cookie_count < 3:
print("wow")
else:
print("going to get 5")
>>> from random import randint
>>> [randint(1,21) for i in range(1,11)]
[10, 17, 3, 19, 20, 7, 11, 4, 4, 18]
>>> type("Kavin") -> <class 'str'>
>>> type(1) -> <class 'int'>
>>> type(True) -> <class 'bool'>
>>> type(1.0) -> <class 'float'>
>>> type(len) -> <class 'builtin_function_or_method'>
- abs()
- bool()
- hash()
- help()
- id()
- input()
- int()
- list()
- max()
- min()
- print()
- range()
- reversed()
- round()
- slice()
- sorted()
- str()
- sum()
- type()
- vars()
- mdanki Python_Kavin_Anki.md Python_Kavin.apkg --deck "Kavin::Python"