0% found this document useful (0 votes)
36 views

Python Crash Course

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Python Crash Course

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Python crash course

CTE115 National Diploma


Introduction
• What is a programming Language
• Compiler/Interpreter (Instalation)
• Why do multiple programing language exist
• How does python work (DISSCUSSION)
Setting up Environment
• Download python Interpreter from the website
www.python.org
• Install the setup file (select the default)
• Test your installation by running the “python” key word in your
command prompt
Using the command Line terminal (CLI)
• Some terminal commands are
• LS
• PWD
• CD , cd .. , cd / , cd ~(user directory)
• Clear
• open .
• Echo > name_of_file
• del (to remove file) , deltree(to remove a folder)

Setting up code editor
• Why do we need to set up a code environment/editor (DISSCUSSION)
• Autocompletion
• Debugging
• Code formatting
• Unit test
• Extensions

• Downlaod Visual Studio Code or your preferred text editor


Learning a Language
• Four Things to master in Learning a programming Language
1. The Terms (syntax)
2. Data Type
3. Actions (functions)
4. Best Practice (Data structure)
Python Data Types
Same as C++ we have data types in all programming python datatypes
include
• Int
• Float
• Bool
• Str
• List
• Tuple
• Set
• Dict

These are referred to as fundamental/primitive data types


Variables
• All languages have variable
• Variable store information that can be used in our program
• Assigning a value to a variable is referred to as binding

Ex:
1. Create variable in both python and C++ programming language
respectively
2. In Two paragraphs, discuss on variables
Rules in naming variable
All though we can name a variable with any name of our choice, it is
preferable to give your variable a meaningful name. below are rules to
follow in naming a variable in python
1. Snake_case
2. Start with lowercase or underscore
3. Letters, numbers, underscore
4. Case sensitive
5. Don’t overwrite keywords
String
• A string is a sequence of characters, it is denoted either with a single or
double quote in most programming language. Example of a string
“we are learning data structure”

• Three single quote in python is used for multiline string


‘’’
This is a
Multi line
String

‘’’’
• The concept of Concatenation (adding strings together)
Type conversion
In some instances we might be force to convert a data type from initial
state to another
The process of Converting data type from one form to another is called
type conversion
Example:
Formatted strings
• Activity:
Read on formatted strings and its advantages
String Index
• All string are represented with a number called index
• Same index in arrays/list
• Example
Immutability
• The process of not supporting element reassignment
Exercise (type conversion)
Write a python program that will guess a users age base on the birth
year given.

• Hint: user should input only year of birth


• Final output: you are x years old. Where x should be the actual users
age
• Expect a “typeError” google your way out
List (Arrays) DS
• Ordered sequence of object or collection of items
• List can be of any data type
• In most programming language list are regarded as Arrays
• The symbol of list is a square bracket [1,2,musa, true,10.5]
• List also have indexing just like strings
• List are mutable while strings are not
• List slicing is the process of breaking a list into smaller list for
examples refer to jupyter notebook
List
• List and Array are use synonymous in programming Language.

• In most programming Language it is called Array while “list” is python


specific

Exercise:
Create a list of numbers traverse through it, find the sum and average
of the numbers

You might also like