24
#Python Basics, Python 101!
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python language is incredibly easy to use and learn for new beginners and newcomers. The python language is one of the most accessible programming languages available because it has simplified syntax and is not complicated, which gives more emphasis on natural language.
The syntax of the Python programming language is the set of rules which defines how a Python program will be written.
A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE. A logical line is created from one or more physical lines.
A line contains only spaces, tabs, form feeds possibly a comment, is known as a blank line, and Python interpreter ignores it.
A physical line is a sequence of characters terminated by an end-of-line sequence
A Python program is divided into a number of logical lines and every logical line is terminated by the token NEWLINE. A logical line is created from one or more physical lines.
A line contains only spaces, tabs, form feeds possibly a comment, is known as a blank line, and Python interpreter ignores it.
A physical line is a sequence of characters terminated by an end-of-line sequence
name = "Jane" # this variable stores the string Jane
print("Hello", name)
Python uses whitespace (spaces and tabs) to define program blocks whereas other languages like C, C++ use braces ({}) to indicate blocks of codes for class, functions or flow control.
A comment begins with a hash character(#) which is not a part of the string literal and ends at the end of the physical line. All characters after the # character up to the end of the line are part of the comment and the Python interpreter ignores them.
name = input("enter your name")
# comment
print("hello", name)
A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ].
fruits = ["mangoes", "bananas", "orange"]
print(fruits)
to add to a list we use the append function.
fruits = ["mangoes", "bananas", "orange"]
fruits.append("lemon")
print(fruits)
To remove items from a list the .remove function is used.
Python tuples are a data structure that store an ordered sequence of values. Tuples are immutable. This means you cannot change the values in a tuple. They let you store an ordered sequence of items. For example, you may use a tuple to store a list of employee names.
fruits = ("mangoes", "bananas", "orange")
print(fruits)
Dictionary in Python is an ordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds key:value pair. Key-value is provided in the dictionary to make it more optimized.
chris = {
"name": "Chris Murimi",
"age": 23
}
print(chris)
Sets are used to store multiple items in a single variable. Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage. A set is a collection which is both unordered and unindexed.
Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand. For example: >>> 2+3 5. Here, + is the operator that performs addition.
Operators type in python:
Operators type in python:
24