Why this technology is relevant and what the scope.
Python is a general-purpose and high-level programming language. You can use Python for developing desktop GUI applications, websites, and web applications. Also, Python, as a high-level programming language, allows you to focus on the core functionality of the application by taking care of common programming tasks
After following this resource what you will learn.
Summary of what learn to get started.
Details about the technology and learning materials.
Python Indentation
Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
for example:
if 5 > 2:
print("Five is greater than two!")
print("This line will be printed.")
# This line will be printed.
Python is a very simple language and has a very straightforward syntax. The simplest directive in Python is the "print" directive - it simply prints out a line
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
String literals in python are surrounded by either single quotation marks or double quotation marks.
'hello'
is the same as "hello"
.
You can display a string literal with the print()
function:
x = 5
y = "John"
print(x)
print(y)
# 5
# john
A list is a collection which is ordered and changeable. In Python, lists are written with square brackets.
Example:
thislist = ["apple", "banana", "cherry"]
print(thislist)
# ["apple", "banana", "cherry"]
A tuple is a collection which is ordered and unchangeable. In Python, tuples are written with round brackets.
Example:
thistuple = ("apple", "banana", "cherry")
print(thistuple)
# ("apple", "banana", "cherry")
A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets.
thisset = {"apple", "banana", "cherry"}
print(thisset)
# {"apple", "banana", "cherry"}
A dictionary is a collection which is unordered, changeable and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values.
Example:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
# {"brand": "Ford", "model": "Mustang", "year": 1964}
if
An "if statement" is written by using the if keyword.
Example:
a = 33
b = 200
if b > a:
print("b is greater than a")
elif
The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition".
Example:
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else
The else keyword catches anything which isn't caught by the preceding conditions.
Example:
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")
Python has two primitive loop commands:
while
loopsfor
loopsWith the while
loop we can execute a set of statements as long as a condition is true.
Print i as long as i is less than 6:
i = 1
while i < 6:
print(i)
i += 1
A for
loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
This is less like the for keyword in other programming languages and works more like an iterator method as found in other object-orientated programming languages.
With the for loop, we can execute a set of statements, once for each item in a list, tuple, set, etc.
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
def
keyword:def my_function():
print("Hello from a function")
my_function()
# Hello from a function
<aside> 👶 Level: Beginner
</aside>
<aside> 💼 Career Path: ‣
</aside>
Automate the Boring Stuff with Python
Free Python Tutorial - Introduction To Python Programming
TinkerHub Foundation - Creating talents with emerging technology skills