installation, sample usage, strings and oop telerik software academy software quality assurance
DESCRIPTION
On MAC, Linux and WindowsTRANSCRIPT
Python OverviewInstallation, Sample Usage, Strings and OOP
Telerik Software Academyhttp://academy.telerik.com
Software Quality Assurance
Table of Contents
Installing and Running Python Fundamentals of Python
development Data types Control structures: loops,
conditionals Functions Object-oriented programming
Installing PythonOn MAC, Linux and Windows
Installing Python
On MAC Homebrew can be used$ brew install python
On Linux Part of Linux is built with Python, so it
comes out-of-the-box On Windows
Download the installer from https://www.python.org/
Add the installation path to System Variables $PATH
Installing Python on Windows and MAC
Live Demo
Running Python Open the CMD/Terminal and run: You can run python code:
Print the numbers from 0 to 4
$ python
for i in range(5): print(i)
sum = 0for i in range(5, 10): sum += Iprint(sum)
Sum the numbers from 5 to 9
Significant whitespace matters
a lot
Significant Whitespace
Significant whitespace is a way to write code in python This is actually the identation
Significant whitespace creates blocks in python code It is the equivalent of curly brackets
({ }) in other languages
Python FundamentalsData types, Control Structures and
more
Python Fundamentals
Python supports all the primary data types: int - integer numbers
int(intAsString) parses a string to int float - floating-point numbers
float(floatAsString) parses a string to float
none – like null bool – Boolean values (True and
False)
Data TypesLive Demo
Control Structures Python supports conditionals:if conditionOne: # run code if conditionOne is Trueelif conditionTwo: # run code if conditionOne is False # but conditionTwo is Trueelse # run code if conditionOne and # conditionTwo are False
The conditions are True-like and False-like i.e. "String", 0, none are evaluated to
True While ""(empty string), any number or
object are evaluated to False
Conditional StatementsLive Demo
Loops There are two types of loops in Python for loopfor i in range(5):
# run code with values of i: 0, 1, 2, 3 and 4
names = ['Doncho', 'Asya', 'Evlogi', 'Nikolay', 'Ivaylo']for i in range(len(names)): print('Hi! I am %s!'%names[i]);
while loopnumber = 1024binNumber = '';while number >= 1: binNumber += '%i'%(number%2) number /= 2print(binNumber[::-1])
LoopsLive Demo
Functions in PythonSeparate the code in smaller and
reusable pieces
Functions in Python Functions in Python:
Are defined using the keyword "def" Have an identifier A list of parameters A return type
def toBin(number): bin = '' while number >= 1: bin += '%i'%(number%2) number /= 2 return bin[::-1]
Functions in PythonLive Demo
Modules in PythonHow to separate the code in different
modules
Modules in Python Python applications are separated
into modules These module represent just a list of
functions and or classes To use all functions from a module numeralSystems:
import numeralSystemsprint(numeralSystems.toBin(1023))print(numeralSystems.toHex(1023))
from numeralSystems import toBin as bin
A single function:
Or some functionsfrom numeralSystems import toBin as bin, toHex as hex
Modules in PythonLive Demo
Classes and OOP
Classes and OOP
Python has classes and inheritance
class Person: lastPersonId = 0 def __init__(self, name): self.__id = ++lsatPersonId self.__name = name def getId(): return self.__id def getName(): return self.__name def setName(newName): self.__name = newName
Classes and OOPLive Demo
форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно
програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки
уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop
уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC
безплатен курс "Разработка на софтуер в cloud среда"
BG Coder - онлайн състезателна система - online judge
курсове и уроци по програмиране, книги – безплатно от Наков
безплатен курс "Качествен програмен код"
алго академия – състезателно програмиране, състезанияASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NET
курсове и уроци по програмиране – Телерик академия
курс мобилни приложения с iPhone, Android, WP7, PhoneGapfree C# book, безплатна книга C#, книга Java, книга C# Дончо Минков - сайт за програмиране
Николай Костов - блог за програмиранеC# курс, програмиране, безплатно
?? ? ?
??? ?
?
? ?
??
?
?
? ?
Questions?
?
Python Overview
http://academy.telerik.com