Escolar Documentos
Profissional Documentos
Cultura Documentos
How many
programming
languages do you
know?
SAY, APART FROM C, JAVA AND OBVIOUSLY, PYTHON.
ASSEMBLY LANGUAGES
Advantages or
Disadvantages of
being High/Low level?
SPEED OF EXECUTION/EASE OF
UNDERSTANDING/PORTABILITY
What makes up a
Program?
ITS CONSTITUENT PARTS.
What do Computer
Scientists do?
IN A VERY BROAD SENSE OF THE TERM COMPUTER
SCIENTISTS
Like engineers, they design things, assembling components into systems and
evaluating tradeoffs among alternatives.
Like scientists, they observe the behavior of complex systems, form hypotheses,
and test predictions.
About Python
THE LANGUAGE WE ARE GOING TO LEARN
Python
Python was conceived in the late 1980s by Guido van Rossum.
Its first implementation was started in 1989
Object Oriented
Imperative
Functional Programming
Procedural Styles.
10
Versions of Python
Version Number
Year of Release
1991-1999
2.0
2000
3.0
2008
11
Version 2 or 3?
Wednesday, December 24, 2014
12
Philosophy of Python
The core philosophy of the language
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Readability counts.
13
Learning a Language
ANY LANGUAGE.
14
15
DIFFERENCES?
NATURAL LANGUAGE
FORMAL LANGUAGE
16
The structure is very important, so it is usually not a good idea to read from top
to bottom, left to right.
learn to parse the program in your head, identifying the tokens and interpreting
the structure.
The details matter!
No Spelling mistakes.
No punctuation errors!
17
What is grammar?
18
Example: English
CHARACTERS:
ABCDEFGHIJKLMNOPQRSTUVWXYZ , . : ; ?
WORDS:
APPLE
BALL
CAT
DOG\
Bigger Words:
ABHORRENCE
BENEFICIARY
COMPREHENSION
DEBUGGING
PHRASES:
SENTENCES:
DOG CHASED THE CAT BECAUSE IT ATE THE MOUSE, WHICH WAS DWELLING IN
THE HOUSE.
19
Features of a language?
Syntax Tokens Basic elements that make up words and sentences along
with symbols.
Structure The way tokens are arranged.
20
Learning Python
BREAKING IT DOWN
21
Tokens
Characters: [a-z A-Z 0-9]
Operators: [/ , //, **, *, +, -, %, =, >, <, >=, <=, ==, !=]
Variables
Keywords
22
Variables
VARIABLES AND KEYWORDS FORM TOKENS
23
Variables
A variable is a name that refers to a value.
An assignment statement creates new value and gives them variable names:
24
int a = 2;
a = 2;
int b = a
25
a=1
a=2
b=a
26
Special Variable
In interactive mode, the last printed expression is assigned to the variable _.
27
Keywords
WORDS WHICH ARE RESERVED AND CAN NOT BE USED
AS INDENTIFIERS
28
Keywords
1.
'False'
12. 'elif'
23. 'lambda'
2.
'None'
13. 'else'
24. 'nonlocal'
3.
'True'
14. 'except'
25. 'not'
4.
'and'
15. 'finally'
26. 'or'
5.
'as'
16. 'for'
27. 'pass'
6.
'assert'
17. 'from'
28. 'raise'
7.
'break'
18. 'global'
29. 'return'
8.
'class'
19. 'if'
30. 'try'
9.
'continue'
20. 'import'
31. 'while'
10. 'def'
21. 'in'
32. 'with'
11. 'del'
22. 'is'
33. 'yield'
29
Remembering Keywords
>>>Import keyword
>>>keyword.kwlist
>>>keyword.iskeyword(string)
>>>dir(keyword)
30
Operators
AS SYMBOLS ARE IN MATHEMATICS AND CHEMISTRY,
OPERATORS ARE IN PROGRAMMING LANGUAGES.
31
Operators
1.
(Division)
9.
2.
//
(Floor Division)
10. <
3.
** (Exponentiation)
11. >=
4.
(Multiplication)
12. <=
5.
(Addition)
13. ==
6.
(Subtraction)
14. !=
7.
(Modulus)
8.
(Assignment)
>
32
Data Types
EVERYTHING IS AN OBJECT.
33
1,
31231,
123491348
Float
1.0, 3.1415,
0.13123
Complex
1+3j, 0+0j,
3-2j
34
abc,
0123,
Lists
[1, 2, 3]
Tuples
1, 2, 3
b, abc
Dictionaries
hello
1, a, abc
35
>>>type(a)
36
Expressions
EXPRESSIONS AS PHRASES.
37
Expressions
a+b/c-d*e
(a+b)/(c-d)*e
38
Input
input() Method:
variable = input(String: )
But the return type is string.
To convert into integer, use int() method.
39
What are
programming
languages used for?
FOR PROBLEM SOLVING!
40
41
Write a Temperature
converter
CONVERT TEMPERATURE FROM FAHRENHEIT TO
CELSIUS
AND VICE VERSA
42
Tc=(5/9)*(Tf-32)
Tf=(9/5)*Tc+32
FORMULA FOR CONVERSION
43
Sample session
Temperature converter
Enter a temperature: 20
Convert to (F)ahrenheit or (C)elsius? F
20 C = 68 F
44
Doubts and/or
queries?
ASK AWAY!
45
Suggestions?
Tell Us!
DROP A MAIL TO:
PYCLUBGECA@GMAIL.COM
46
Thank You!
PYCLUB GECA TEAM THANKS YOU!
47