Skip to content

10.Python Notes

0. Study Questions

  • What is Python? Python is a programming language
  • Machine Language(0 and 1)
  • A programming language connects human language and machine language

  • How Does Python Works?

  • Python uses libary with code already in it (this makes programing easier)
  • After you type code into Python, Python interprator traslates it into machine language. The machine language then comands the machine to operate the task.

  • How is VSCode and Python Related?

  • VSCode is the most poplular computer language IDE (Integrated Development Environment)
  • IDE provides a lot of supporting features in terms of coding, e.g. versioning control, debugging.
  • VSCode supports Python very well, it is the second most popular Python IDE, after PyCharm.

Python: Programming: A Beginners Guide to Learn Python in 7 Day

Introduction

  • This book will only teach the basics
  • Python is the easiest language to learn
  • This makes it a great way to start coding
  • This will help you move on to more complicated languages
  • Python has a great framework and community to help you
  • Python is used for a lot of different reasons
  • This makes it great for all sorts of people

1: Setting Up Your Environment

  • How to set up python for Windows 7, 8, 8.1, and 10
  • Download Python
  • Run the Python Installer
  • Under heading Advanced Options choose where you want python to be installed
  • Set up the PATH varible for systems
  • Open Control Panel
  • Go to Envirment>System Environment Variable>Edit>Environment Varibles
  • Under User Varibler:
    • edit a path
    • make new path
  • click on Start>Windows System>Command Prompt : then type following listed in book
    • This will load Python Interpreter
  • type exit and press enter return back to command prompt
  • Text Editors You need test editor to program
  • Widows
    • notepad
  • Mac
    • Text Wrangler
  • After, save your frist program (something e.g. Firstprog).py

2: Let's Get Programming

  • Math
  • Type formula in pythong command line, you get result on screen start with: sum=x+y print("sum equals",sum)

3: Varibles and Programs in Files

4: Loops, Loops and More Loops

5: Functions

6: Dictionaries, Lists and Tuples

7: The "for" Loop

8: Classes

9: Modules

10: File Input/Output

11: Error Handling

Conclusion

Addition with Python

To print words: print("word")

Operand

Command Name Example Output
+ Addition 5+7 12
- Subtraction 7-5 2
* Multiplication 5*7 35
/ Division 12/3 4
% Remainder 19%3 1
** Exponent 2**4 16

start with: sum=x+y print("sum equals",sum)

Varibles

Varibles is where you assign a value to it. E.g. v=1 You can use this in problems. Instead of putting the numbers, add the varibles. E.g.: x=1 y=2 sum=x+y print("sum is:",sum)

Programs in Files

  1. Write text in another app like notebook like writing python.
  2. Move it into a folder and rename with a .py.
  3. Go back to python.
  4. Press file and open the file.
  5. Play code

Loops

while loop: a=0 while a < 10: a=a+1 print (a) answer: 1 2 3 4 5 6 7 8 9 10

use if for condition

if[donditions to be met]: {do this} {and this} {and this} {but this happens regardless} {because it isnt indented}

y=1 if y == 1: print("y still equals 1, i was just checking")

print ("we are going to show the even numbers up to 20") n=1 while n <= 20: if n % 2 == 0: print(n) n=n+1 print ("there, it's done")

Expression Function
< Less than
>= Less than or equal to
> Greater than
>= Greater than or equal to
!= not equal to
<> alternative expression for not equal to
== equal to

if{conditionss}: {run this code} elif{conditions}: {run this code} elif{conditions}: {run this code} else: {run this code}

Simple Calculator Code

code

Funtions

def function_name(parameter_1,parameter_2) {this is the code that is in the function} {more code} {more code} return{value(e.g. text or number)to return to the main program}