0% found this document useful (0 votes)
23 views43 pages

Session One

Uploaded by

Sammy Ay-man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views43 pages

Session One

Uploaded by

Sammy Ay-man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Python

Intro
• What is Programming: Instructions have given to machine to do
some tasks using Programming languages.
•.
• Programming languages: It is a way of communication that humans
understand because it is close to human language converted inside
the machine into 0 , 1
Types of Programming languages
Low level , High level
Interpreted , Compiled
Programming ,Scripted
Open source , not open source
Support OOP , not supporting OOP
What’s Python?
• Python has a simple, easy to learn syntax, which emphasizes
readability. Applications written in Python can run on almost any
computer, including those running Windows, macOS, and popular
distributions of Linux. Furthermore, the ecosystem contains a rich
set of development tools for writing, debugging, and publishing
Python applications.

• Python is one of the most popular and fastest growing


programming languages in the world. It's used for all sorts of
tasks, including web programming and data analysis, and it has
emerged as the language to learn for machine learning.
Con.
• Python is one of the most popular programming languages in
the world. Created in the early 1990s, Python can be employed
for a wide range of uses, from automating repetitive tasks and
writing web apps to building machine learning models and
implementing neural networks. Researchers, mathematicians,
and data scientists in particular like Python because of its rich
and easy to understand syntax and the wide range of open-
source packages available..
• An easy programming language, with powerful programming
capabilities.
Con.
• Interpreted language
• Not Compiled to a binary form of machine language.
• Interpreter converts the code to binary ‘on the fly’ at each time it
is run. (Slower)
Why Python?
• Easier syntax, more readable, shorter programs.
• Has large libraries of various built-in functions.
• Portable, runs on Unix, Mac, and windows.
• Scalable, used for small and large programs.
• Interactive, can write and test programs from terminal.
Indentation (very important)
• Indentation is one of the greatest future in python.
It’s free(open source)
• Downloading and installing Python is free and easy Source code is
easily accessible.
Python is object-oriented
• Structure supports four concepts
It’s powerful
Library utilities
Third party utilities(Numeric,Numpy,Pandas)
It’s easy to use
It’s easy to learn
Compiler vs Interpreter
Compiler vs Interpreter
• Compiler transforms code written in a high-level programming
language into the machine code, at once, before program runs,
whereas an Interpreter coverts each high-level program statement,
one by one, into the machine code, during program run.
• Compiled code runs faster while interpreted code runs slower.
• Compiler displays all errors after compilation, on the other hand, the
Interpreter displays errors of each line one by one.
• Compiler takes an entire program whereas the Interpreter takes a
single line of code
Installing Python
• https://www.python.org/downloads/

• PyCharm
• https://www.jetbrains.com/pycharm/download/#section=windows

• OR->>> Anaconda
• https://www.anaconda.com/products/distribution/start-coding-
immediately
Interactive Programming
•>>> print(“Hello world!”)
•Hello world!
• Python as Calculator
>>> 5+5
10
>>> 10.5-2*3
4.5
>>> 10**2

100 ** is used to calculate powers


>>> 17.0 // 3

5.0 floor division discards the fractional part


>>> 17 % 3

2 the % operator returns the remainder


>>> 5 * 3 + 2

17 * takes precedence over +, -


Variables
• Variables are containers that store numbers, strings, and other data types
and structures.
• Variables are names given to values that can be changed.
• Variables are assigned values using the equal sign (=).
>>> first_name = ’Ali'

>>> dna_sequence = "gtcgcctaaccgtatatttttcccgt"

• A variable cannot be used if not assigned a value, an error


occurs.
>>> dna

NameError: name 'dna' is not defined


Variables
• Naming
• Select meaningful names: first_name , is better than x.
• Follow naming rules:
• Case-sensitive :
• one = 1
• oNe = 1
• One= 1
• Consists of letters and numbers combinations, and underscore.
• One1, one_1, one.
• Numbers should not be the first letter.
• Invalid: 1one
• No special characters.
• one#, one@1
Variables
• Assigning values to variables

>>> a=3

>>> a

>>> b=a

>>> b

>>> b=b+3

>>> b
Data Types: Number Types

int, float, complex

1. Integer numbers: 2. Real numbers: 3. Complex numbers:

>>> type(4) >>> type(4.5) >>> type(3+2j)

<type 'int’> <type ’float’>


<type ’complex'>

>>> 17/5
>>> (2+1j)**2

(3+4j)
>>> float(17)/5
Boolean
• type is one of the built-in data types provided by Python, which
represents one of the two values .(True or False).
Data Types: Strings

• Single quote:
>>> ’atg’

’atg’

• Double quote:
>>> ”atg”

’atg’

>>> ’This is a codon, isn’t it?’

Invalid Syntax

>>> ” This is a codon, isn’t it?” # Or >>> ’This is a codon, isn\’t it?’

This is a codon, isn’t it?


String Operators
• Escape character: Backslash ‘\’ , gives special meaning for the following character.
• To produce more readable outputs: print()
• String Operators:
• Concatenate +
• Copy or replicate * Construct Meaning
• Checks if first IS in second string in \n Newline
• Checks if first IS NOT in second string not in
\t Tab
>>> ’atg’ + ’gcc’
\\ Backslash
’atggcc’
\” Double Qoute
• Double quote:
>>> ’atg’ * 3

’atgatgatg’

>>> ’tg’ in ’atgatgatg’

True

>>> ’tc’ in ’atgatgatg’

False
Input and Output Formatting
• You can refer to variables or expressions in a string using f

year = 2016
event = 'Referendum'
Results of the {year} {event}
str= 'Results of the {year} {event}'
Results of the 2016 Referendum
print(str)
str= f'Results of the {year} {event}'
print(str)
Type Conversions

Function Description

int(x) Converts x to an integer

float(x) Converts x to a floating point number

str(x) Converts x to a string

chr(x) Converts an integer to a character


Constants
• A constant is a type of variable that holds values, which
cannot be changed. In reality, we rarely use constants in
Python. Constants are usually declared and assigned on a
different module/file.
Comments
>>> name = “ahmed“ # Single line comment
'''
Multi Line
comment
'''
Arithmetic Operators
Arithmetic operators are used with numeric values
to perform common mathematical operations
Assignment Operators
Assignment operators are used
to assign values to variables.
Identity Operators

• Identity operators are used to compare the


objects, not if they are equal, but if they are
actually the same object, with the same memory
location
Membership Operators
Membership operators are used to test if a sequence is
presented in an object

You might also like