DEV Community

VIDHYA VARSHINI
VIDHYA VARSHINI

Posted on

Getting started with Python

Introduction:
What is programming: It is a way of communicating with the machine using binary code.
What is interpreter: An interpreter translates and executes code step-by-step instead of converting the whole program into machine code at once.
What is compiler: It is a program that translates high level source code into machine code (binary).

How python files run at backend: After entering as python3 filename, it will first convert into byte code.
python.py → bytecode (.pyc) → executed by PVM
This will run on every server.
Python is both compiler and interpreted language.

nano linux commands:

  1. pwd - print working directory (to check where the file is located).
  2. mkdir - make directory
  3. ls - list
  4. cd - change directory
  5. rmdir - remove directory

import this - displays the Zen of Python
quit() - to get exit from the program.

Indentation - It is the spaces (or tabs) given at the beginning of the line of code.

Swapping of two variables:

a = 17
b = 5
a = a+b
b = a-b
a = a-b
print(a,b)

Enter fullscreen mode Exit fullscreen mode

Output:

5 17
Enter fullscreen mode Exit fullscreen mode

This can also be done using tuple method.

a = 10
b = 5
a,b = b,a
print(a,b)
Enter fullscreen mode Exit fullscreen mode

Output:

5 10
Enter fullscreen mode Exit fullscreen mode

Top comments (0)