title: Meet, Python! content_class: flexbox vcenter centered
World's easiest and arguably most powerful programming language.
title: Who uses Python? content_class: flexbox vcenter centered
and many, many more. . .
title: Quick feature check class: fill
-
Very-high-level, interpreted, loosely and dynamically typed, object-oriented
-
Clean, readable syntax
-
Comfortable level of abstraction, automatic memory management
-
Does not force object orientation
-
Extensive collection of standard modules, great community support
-
Can be, and is, used for a large number of application types
-
Easily extensible, plays nice with applications written in other programming languages
-
Easy to learn, get started, and build things, has common sense
title: class: nobackground content_class: flexbox vcenter centered
source: xkcd.comThis is a title with the event branding.
title: Common Sense? class: fill
#include <iostream> using namespace std; int main() { cout << "Hello, world!" << std::endl; return 0; }
public class HelloWorld { public static void main(String [] args) { System.out.println("Hello, world!"); } }
title: Common Sense! class: fill
print "Hello, World!"
- Clean, comprehensible syntax.
- No braces. Uses tab spaces as delimiters.
Impressed already?
title: Ready to hack? class: nobackground content_class: flexbox vcenter centered
$ pythonor
Start > Python27 > IDLE --- title: Look, we have a calculator! class: fill
Your Python shell can be used to do some real quick calculations. Don't reach out for your calculator ever again.
>>> 3 + 2 5 >>> 98 - 56 42 >>> (60 - 57) * 11 33 >>> (124 - 88) / 9 4
Looks cool, huh?
title: class: nobackground content_class: flexbox vcenter centered
title: Operators, numbers and variables class: fill
>>> 57 / 8 # integer division by default 7 >>> 57.0 / 8 # coercion to float division 7.125 >>> PI = 3.14 # PI is a variable >>> r = 2.5 >>> area = 2 * PI * r**2 # ** is used for exponentiation >>> area 39.25 >>> x = 1 >>> y = z = 5 # multiple variable assignment >>> X + y * z Traceback (most recent call last): # Drats! We have an error! File "<input>", line 1, in NameError: name 'X' is not defined # variables are case-sensitive! >>> x + y * z 26
title: Imaginary numbers too! class: fill
Complex numbers : real + imag j
>>> z = 4 + 2j >>> z (4+2j) # complex number tuple >>> z.real # property 4.0 >>> z.imag 2.0 >>> z.conjugate() # method (4-2j) >>> abs(z) # abs() is a built-in method in Python 5
title: Some nifty functions class: fill
>>> x, y = 42, 6.9 # multiple inline assignments >>> float(x) # converts to floating point 42.0 >>> int(y) # converts to an integer 6 >>> round(y) # rounds off to the nearest integral number, returns a float 7.0 >>> long(x) # converts to long int 42L >>> max(x, y) 42 >>> min(x, y, 0, -3) -3
title: class: nobackground content_class: flexbox vcenter centered
title: Let's print something! class: fill
>>> 'CampusHash' 'CampusHash' >>> "Hello, world!" 'Hello, world!' >>> "And then everyone shouted, 'We love CampusHash!'" # nested quotes "And then everyone shouted, 'We love CampusHash!'" >>> 'I said, "Well, that\'s great."' # escaping with \ >>> person, emotion, thing = "Minions", "love", "banana" >>> person+emotion+thing 'Minionslovebanana' >>> person + ' ' + emotion + ' ' + thing + '.' 'Minions love banana.' >>> thing * 5 'bananabananabananabananabanana'
title: Let's 'print' something! class: fill
>>> print 'Gru' Gru >>> movie = 'Despicable Me' >>> movie 'Despicable Me' >>> print movie Despicable Me # no quotes!
- print is not a function. It is an operator.
- Anything that you operate print on, will be printed to the standard output.
title: Anatomy of a String class: nobackground content_class: flexbox vcenter centered
Tip : Google for 'Monty Python's Flying Circus'.title: Not just your regular String class: fill
- There is no char in Python. Only str.
- Strings are immutable, i. e., they cannot be changed.
- Strings support splicing.
- Lots of in-built methods and properties to operate on strings.
>>> name = "Minion" >>> name[3] 'i' >>> name[3] = 'x' Traceback (most recent call last): File "<input>", line 1, in TypeError: 'str' object does not support item assignment >>> name[::-1] # This one's magic! 'noiniM' --- title: class: nobackground content_class: flexbox vcenter centered --- title: class: fill content_class: flexbox vcenter centered It is analogous to an array. --- title: Lists - Feature Check class: fill - Lists are collections of items (strings, integers, or even other lists). - Each item in the list has an assigned index value. - Lists are enclosed in [ ]. - Each item in a list is separated by a comma. - Unlike strings, lists are mutable, which means they can be changed.>>> fruits = ['apple', 'banana', 'orange'] >>> fruits[0] 'apple' >>> mix = ["1", "hello", 2, "world"] >>> mix[-1] 'world'
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered
title: Dictionaries - Feature Check class: fill
-
Dictionaries are collections of items that have a "key" and a "value".
-
Python dictionaries are also known as associative arrays or hash tables.
-
They are just like lists, except instead of having an assigned index number, you make up the index.
-
Dictionaries are unordered, so the order that the keys are added doesn’t necessarily reflect what order they may be reported back.
-
Use {} curly brackets to construct the dictionary.
-
Look up the value associated with a key using [].
-
Provide a key and a value.
-
A colon is placed between key and value (key:value).
-
Each key must be unique and each key can be in the dictionary only once.
title: class: nobackground content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered
title: Function rules class: fill
-
A function in Python must be defined before it’s used.
-
Create a function by using the keyword “def” followed by the functions name and the parentheses ().
-
The function has to be named plus specify what parameter it has (if any).
-
The keyword "def" is required and must be in lowercase.
-
The name can be anything you like.
-
The end of the line has to end with a colon (:)
-
The function often ends by returning a value using return.
-
The code inside the function must be indented.
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered
title: class: nobackground content_class: flexbox vcenter centered
title: class: fill content_class: flexbox vcenter centered