Introduction to Python

What is Python?

  • Python is an interpreted, high-level, general-purpose programming language.

  • Python’s design philosophy emphasizes code readability with its notable use of significant whitespace

Key Points

  • Designed by: Guido van Rossum

  • Typing discipline: Duck, dynamic, gradual

  • Stable release: 3.8.2 / 24 February 2020; 25 days ago

  • Preview release: 3.9.0a4 / 26 February 2020; 23 days ago

  • Paradigm: Multi-paradigm: functional, imperative, object-oriented, reflective

Why Python?

  • Python Is Free and Open-Source

  • Python Is Popular, Loved, and Wanted

  • Python Has a Friendly and Devoted Community

  • Python Has Elegant and Concise Syntax

  • Python Is Multi-Platform

  • Python Supports Multiple Programming Paradigms

  • Python Offers Useful Built-In Libraries

  • Python Has Many Third-Party Packages

  • Python Is a General-Purpose Programming Language

  • Python Plays Nice with Others

Why Python Rocks for Research?

  • Holistic Language Design

  • Readability

  • Balance of High Level and Low Level Programming

  • Language Interoperability

  • Documentation System

  • Hierarchical Module System

  • Data Structures

  • Available Libraries

  • Testing Framework

Getting Started

Printing Message

print("Hello World!")
Hello World!

Python as a Calculator

2+2 
4
3 - 2
1
3 * 2 
6
6 / 2
3.0
3 * 2 + 5 
11

Variables

  • What is Variables?

  • Creating / Declaration of Variables

  • Naming Conventions

  • Restrictions / Reserved Words / Identifiers

a = 10 
print(a)
10
b = 10.5 
print(b)
10.5
type(b)
float
print(a)
10.5
b = 10.5 
print(b)
10.5
print(a)
10.5
name = "abul"
print(name)
abul
type(name)
str
myName = "Jubayer"
my_name = "Jubayer"
sayHello = "Hello"
import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
False = "Sammo"
  File "<ipython-input-33-044471a12d85>", line 1
    False = "Sammo"
                   ^
SyntaxError: can't assign to keyword
as = "Student"
  File "<ipython-input-34-73a552ff327a>", line 1
    as = "Student"
     ^
SyntaxError: invalid syntax
class = "11"
  File "<ipython-input-35-eae6fc40a0c2>", line 1
    class = "11"
          ^
SyntaxError: invalid syntax
import = "this"
  File "<ipython-input-36-47ce75f72138>", line 1
    import = "this"
           ^
SyntaxError: invalid syntax

Statements

Instructions that a Python interpreter can execute are called statements. For example, a = 1 is an assignment statement.

a = 10 
b = 10.5 
name = "Sammo"

Comments

# Print Hello 
print("Hello")
Hello

Data Types

Data is the collection of facts! data cen be anything like numbers, audio, images, video, text, papers.

  • Integers(int)

  • Floating Point(float)

  • Complex(j)

  • Strings

Integers

x = 10 
type(x)
int
y = 5.5 
type(y)
float
c = 2 + 6j 
type(c)
complex
my_name = "Jubayer"
type(my_name)
str
name = 'abul'
type(name)
str