installation, sample usage, strings and oop telerik software academy software quality assurance

24
Python Overview Installation, Sample Usage, Strings and OOP Telerik Software Academy http://academy.telerik.com Software Quality Assurance

Upload: -

Post on 18-Jan-2018

231 views

Category:

Documents


0 download

DESCRIPTION

On MAC, Linux and Windows

TRANSCRIPT

Page 1: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Python OverviewInstallation, Sample Usage, Strings and OOP

Telerik Software Academyhttp://academy.telerik.com

Software Quality Assurance

Page 2: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Table of Contents

Installing and Running Python Fundamentals of Python

development Data types Control structures: loops,

conditionals Functions Object-oriented programming

Page 3: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Installing PythonOn MAC, Linux and Windows

Page 4: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 5: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Installing Python on Windows and MAC

Live Demo

Page 6: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 7: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 8: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Python FundamentalsData types, Control Structures and

more

Page 9: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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)

Page 10: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Data TypesLive Demo

Page 11: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 12: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Conditional StatementsLive Demo

Page 13: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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])

Page 14: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

LoopsLive Demo

Page 15: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Functions in PythonSeparate the code in smaller and

reusable pieces

Page 16: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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]

Page 17: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Functions in PythonLive Demo

Page 18: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Modules in PythonHow to separate the code in different

modules

Page 19: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 20: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Modules in PythonLive Demo

Page 21: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Classes and OOP

Page 22: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

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

Page 23: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

Classes and OOPLive Demo

Page 24: Installation, Sample Usage, Strings and OOP Telerik Software Academy  Software Quality Assurance

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен 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