Day 1

Installing python

one can install python using package manager depending upon the operating system you are using. As I have a windows machine and ubuntu using linux on windows subsystem. I can install python from https://python.org. And Ubuntu I can use below command to install python.

1
sudo apt-get install python3

Running python

To run python you would call python3 which open Python interpreter. On that you can type print(“Hello World”) to run your first python code which would print Hello World in next line.

To run python code from a file I would need to below text into a file, save suppose as hello.py

1
2
#!/usr/bin/env python3
print("Hello World!")

The file “hello.py” needs to be executable to be run the code. If file is not executable we can do it by chmod +x hello.py

then we can run file by calling it as ./hello.py

White space and indentation

Whitespace and indentation should be perfect for python. If a line is not correctly indented python interpreter would Indentation error. There are few basic rule to follow,

  • Use 4 spaces for indentation
  • Never mix tab and spaces
  • One line blank after functions
  • two lines blank after classes.
  • add a space after “,” in dicts, lists, tuples and argument list and after “:” in dicts
  • Spaces around assignments and comparers
  • no spaces after starting and before ending () brackets/parentheses

Comments

In python on can write comments starting with ‘#’ Still gonna check whether to use ’’’ for multiline comments or not. links:

Modules

Modules are link library which you can in import and run function from it.

Keywords and Indentifier

As any other language there are reserved keywords in python which cannot be used as ordinary identifiers. Below is the list of identifiers. Note: Identifiers are case sensitive they should be used with same casing.

1
2
3
4
5
6
7
and       del      from      not   while
as        elif     global    or    with
assert    else     if        pass  yield
break     except   import    print
class     exec     in        raise
continue  finally  is        return
def       for      lambda    try

We don’t need specify data type with python something similar to javascript where we use var for every type of variable.