Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Python Overview Installation, Sample Usage, Strings and OOP Software Quality Assurance Telerik Software Academy http://academy.telerik.com Table of Contents Installing and Running Python Fundamentals of Python development Data types Control structures: loops, conditionals Functions Object-oriented programming Installing Python On 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 outof-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 for i in range(5): print(i) Sum the numbers from 5 to 9 sum = 0 for i in range(5, 10): sum += I print(sum) Significant whitespace matters a lot $ python 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 Fundamentals Data 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 Types Live Demo Control Structures Python supports conditionals: if conditionOne: # run code if conditionOne is True elif conditionTwo: # run code if conditionOne is False # but conditionTwo is True else # 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 Statements Live Demo Loops There are two types of loops in Python for loop for 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 loop number = 1024 binNumber = ''; while number >= 1: binNumber += '%i'%(number%2) number /= 2 print(binNumber[::-1]) Loops Live Demo Functions in Python Separate 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 Python Live Demo Modules in Python How 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 numeralSystems print(numeralSystems.toBin(1023)) print(numeralSystems.toHex(1023)) A single function: from numeralSystems import toBin as bin Or some functions from numeralSystems import toBin as bin, toHex as hex Modules in Python Live 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 OOP Live Demo Python Overview курсове и уроци по програмиране, уеб дизайн – безплатно курсове и уроци по програмиране – Телерик академия уроци по програмиране и уеб дизайн за ученици програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки курсове и уроци по програмиране, книги – безплатно от Наков уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop free C# book, безплатна книга C#, книга Java, книга C# безплатен курс "Качествен програмен код" безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge форум програмиране, форум уеб дизайн ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NET ASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC алго академия – състезателно програмиране, състезания курс мобилни приложения с iPhone, Android, WP7, PhoneGap Дончо Минков - сайт за програмиране Николай Костов - блог за програмиране C# курс, програмиране, безплатно http://academy.telerik.com