Introduction
Overview
Python is one of the significant programming languages of the
world. It is object oriented and an open source language. So
everyone can learn python programming through a browser
only rather than installing it in their operating language. It is
considered as an easy to learn and maintainable language, so
even kids can start learning python language. Python was
introduced in 1991.It was named it after television show Monty
Python’s Flying Circus.
What is coding and why it is good for kids?
•Everyone can learn to code.
•It’s just like solving a puzzle or a riddle.
•You apply logic, try a solution, experiment a little more, and
then solve the problem.
Good For Kids
•Coding is fun.
•Coding is a valuable job skill.
Computer programming, or coding, is a crucial skill every child should be
learning. We use computers to solve problems, play games, help us work
more effectively, perform repetitive tasks, store and recall information,
create something new, and connect with our friends and the world.
Understanding how to code puts all this power at our fingertips.
Why is python programming the best
choice for kids to start programming?
Python programming is an easy language and it has many
other features which make it easy for kids to start learning
programming. Following are the features of python
programming for kids –
1.Easy Learning
2.Heavy Demand
3.Easy web development
4.Efficient for Machine learning and AI
5.Corporate friendly
Why Python?
•Python is easy to understand,
•Can be used in many different ways
•Quick to learn.
•Also, it is a popular language that runs on almost every
machine and is used at many big, important organizations
like Google, Instagram, NASA, and Spotify.
Python features
• No compiling or linking
• Rapid development cycle
• No type declarations
• Simpler, shorter, more flexible
• Automatic memory management
• Garbage collection
• High-level data types and operations
Who Uses Python
• Google
• Amazon
• NASA
• ...the list goes on...
Python structure
• modules: Python source files or C extensions
–import, top-level via from, reload
• statements
–control flow
–create objects
–indentation matters – instead of {}
• objects
–everything is an object
–automatically reclaimed when no longer needed
Python Interfaces
•IDLE – a cross-platform Python development
environment
•Python Shell – running 'python' from the Command Line
opens this interactive shell
• Sublime editor
•Notepad++
•Jupyter
•Visual studio
For the exercises, we'll use IDLE, but you can try them all
and pick a favorite
Python Installation
If you are on a Windows machine, you probably don’t have
Python installed already. This is because Windows operating
systems don’t usually come with the Python language. That’s
okay, though! We can get it ourselves. :)
In Mac Python is already installed.
1. On your computer, open an Internet browser like Google Chrome
or Mozilla Firefox. In the address bar, type
https://www.python.org/downloads/ Python website’s
2. Download a newer version. Go ahead and click the DOWNLOAD
button.
3. A download will start and will probably go to the bottom of your
window like in the picture.
4 Once your download is complete, click on it to begin the
installation. When you do, a window should pop up.
5. Go ahead and click the Run button.
6 . Make sure to check the ADD
PYTHON 3.7 TO PATH checkbox.
7. Click INSTALL NOW . Python
should begin installing. You should see a
window like this one:
8. Wait for the install to finish and the green bar to be full. Once it is
done, the final screen should appear, saying that your installation
was successful.
IDLE – Development
Environment
•IDLE helps you program in Python
by:
• color-coding your program code
• debugging
• auto-indent
• interactive shell
When you download and install Python, it will also install an
application called IDLE. IDLE is short for Integrated Development
and Learning Environment (that’s a mouthful!), and it is an
integrated development environment, or IDE , that helps us with
writing Python programs. To work in Python, you will need to open
IDLE—opening Python files directly won’t work! Let’s take a look!
1. Click the Windows Start menu.
2 Start typing “idle”, then select the search result IDLE
(Python 3.7 64-bit). Note: Yours might say IDLE (Python 3.7
32- bit) if that’s the kind of machine you have.
3. A window should pop up that
looks like this:
4. Awesome! You opened IDLE on Windows and are now ready to
start writing some code in Python! : )
Example Python
•Hi Python
print “Hi Python!”
•Prints Hi Python!
•Open IDLE and try it out
yourself
•Follow along using IDLE
• Great job! You’ve written your
first line of Python code! You’re
about to learn some awesome
things.
Running & Saving a program
• This is the best part—seeing your code in
action! After you write some code, save it,
and are ready to see it run.
• Great job! You’ve written your first line of
Python code! You’re about to learn some
awesome things.
• Go to the Run option on the menu above
your program and select Run Module. This
will run, or carry out, the instructions in your
program. It will first ask you to save the
program. Let’s call our file YourName.py.
This tells your computer to save the
program as a file called YourName.py,
and the .py part means this is a Python
program.
More than just printing
•Python is an object oriented language
•Practically everything can be treated as an object
•“Hi Python” is a string
•Strings, as objects, have methods that return the result of a
function on the string
Print Function
•One of the most used lines of code in Python is the print() function. We use it
everywhere.
print("Hi Python!")
•The print() function is used when we want to output a string. A string is a
collection of characters, or what we know as text. Strings are a type —just like it
sounds, a type is a way for the computer to understand what kind of input we are
giving it. There are other types, like integers, Booleans, and lists
•—but don’t worry about them yet! We’ll learn about them in next class.
•The print() function takes a few parameters , which are pieces of information
(input) you give a function to do something with. For now, we’ll only use one
parameter, which is the part you put inside the double quotes. The print()
function will take this piece and print it out to the console window.
Comments
Comments are pieces of code that do not get translated by the computer. You use
them as helpful messages you leave for yourself within your code, or as parts of
code you want the computer to ignore. You can create a comment by putting a hash
character (#) before the line you’d like the computer to ignore. This is also called
commenting out a line. As you’ll see, comments also become a noticeable red color
to show you they are comments.
# print("I should not be printed!")
So, if there’s part of your code that you think is causing you problems, you don’t
have to delete it. You can test it by commenting it out:
print("Hello")
# print("You are not working!")
In the code above, it would print the first line (“Hello”), but not the second (“You are
not working!”)—because the hash character signals to the computer, “Don’t print this
line!” How cool is that?
Python Overview
• Programs are composed of modules
• Modules contain statements
• Statements contain expressions
• Expressions create and process objects
Day 1-Assignment 1
• Write something about yourself and save it with python
extension and add comments where necessary.
The World of Variables
• Variables are nothing but reserved memory locations to store values. This means
that when you create a variable you reserve some space in memory.
• Based on the data type of a variable, the interpreter allocates memory and
decides what can be stored in the reserved memory. Therefore, by assigning
different data types to variables, you can store integers, decimals or characters in
these variables.
• Variables are not declared, just assigned
• The variable is created the first time, you assign it a value
• Variables are references to objects
• Everything in Python is an object
Variable name – Identifiers
Variable name is known as identifier. There are few rules that
you have to follow while naming the variables in Python.
1. The name of the variable must always start with either a
letter (a - z, A - B), or an underscore (_). For example:
_str, str, num, _num are all valid name for the variables.
2. The name of the variable cannot start with a number. For
example: 9num is not a valid variable name.
3. The name of the variable cannot have special characters
such as %, $, # etc, they can only have alphanumeric
characters and underscore (A to Z, a to z, 0-9 or _ ).
4. Variable name is case sensitive in Python which
means num and NUM are two different variables in python.
5. In addition, there are some reserved words that you cannot
use as variable name because they already have preassigned
meanings in Python. These reserved words include words like
print, input, if, while etc. We’ll learn about each of them in
subsequent chapters.
Variables example
• Whenever you create a variable, you are allocating space in a
computer’s memory, a storage that can hold values. Variables
are given distinct names to identify their memory locations.
These names are then used as a reference to instruct the
computer to access, edit, save, or retrieve stored data.
• Variable creation and management is a lot more flexible and
straightforward in Python than in most other languages. You
can easily create or declare a variable by using a
syntactically appropriate name and assigning a value to it
using the assignment operator (=). You need not even inform
Python that you want a variable to contain a specific type of
data. Python automatically identifies the data type based on
the values you assign to the variable.
Variables example
• The left operands (in grey) are the names of the variables while the right
operands (in blue) refer to the value assigned to
• The left operands (in grey) are the names of the variables while the right
operands (in blue) refer to the value assigned to the variable. The use of
the assignment operator tells Python that a variable is assigned to store a
particular value. Hence, in the assignment statement “average score =
80.50”, you are basically telling Python that the variable ‘average score’
is set to ‘80.50’. Python, in this case, knows that you are using the
variable ‘average score’ to store a floating point number and there’s
absolutely no need to declare that this variable is going to hold a float.
•Multiple assignments in one statement
•Python accepts multiple assignments in one statement with
this syntax:
•x, y, z = a, b,c
•Assignment of a common value to several variables in a
single statement
•Python allows the assignment of a common value to several
variables in a single statement with the syntax:
•x = y = z = “apple”
Memory Location
To check the memory location of the variables, you’ll use the id()
operator.
Now you can type these assignments:
>>>id(employee)
>>>id(score)
>>>id(counter)
>>>id(comment)
Once you type your assignments and
press ENTER, Python will give you the
memory location -
Data Types in Python
A data type defines the type of data, for example 123 is an integer
data while “hello” is a String type of data. The data stored in
memory can be of many types. Python has various standard data
types that are used to define the operations possible on them and
the storage method for each of them.
The data types in Python are divided in two categories:
1. Immutable data types – Values cannot be changed.
2. Mutable data types – Values can be changed
Data Types in Python
Immutable data types in Python are:
1. Numbers
2. String
3. Tuple
Mutable data types in Python are:
1. List
2. Dictionaries
Python Numbers
Python supports integers, floats and complex numbers.
Number data types store numeric values. Number objects are
created when you assign a value to them. For example −
var1 = 1
var2 = 10
An integer is a number without decimal point for example 5, 6,
10 etc.
A float is a number with decimal point for example 6.7, 6.0,
10.99 etc.
A complex number has a real and imaginary part for example
7+8j, 8+11j etc.
Python Numbers
Python supports four different numerical types −
❑ int (signed integers)
❑ long (long integers, they can also be represented in octal and
hexadecimal)
❑ float (floating point real values)
❑ complex (complex numbers)
Examples
Here are some examples of numbers −
❖ Python allows you to use a lowercase l with long, but it is recommended
that you use only an uppercase L to avoid confusion with the number 1.
Python displays long integers with an uppercase L.
❖ A complex number consists of an ordered pair of real floating-point
numbers denoted by x + yj, where x and y are the real numbers and j is
the imaginary unit.
Integers (int)
Integers are whole numbers with no fractional parts and decimal
point. They can be positive, negative, or zero. Integers can have
unlimited size in Python 3 and are only limited by the available
memory on your computer. Python supports normal integers as
well as octal, hexadecimal, and binary literals:
Examples:
44
4500
-32
0
96784502850283491
# Python program to display numbers
of
# integer data type
# int
num1 = 10
num2 = 100
print(num1+num2)
Output:
110
Floating-Point Numbers (Floats)
Floating-point numbers are real numbers with a decimal point.
Examples:
0.50,
42.50
10500.40
2.5
# Python program to display numbers
of
# float data type
# float
a = 10.5
b = 8.9
print(a-b)
Output:
1.5999999999999996
Complex Numbers
Complex numbers are pairs of real and imaginary numbers. It
takes the form ‘a + bJ’ or ‘a + bj’ where the left operand is a real
number while the right operand is a float (b) and an imaginary
number (J). The upper or lower case letter Jj refers to the square
root of -1, an imaginary number.
Example:
>>> abc = 2 + 4j
>>> xyz = 1 - 2j
>>> abcxyz = abc + xyz
>>>print(abcxyz)
(3+2j)
Variable & DataType - Assignment 2
1. Write a program to assign a value to variable and print its value
2. Write a program to assign multiple values and print.
3. Create three variables mood, strength and rank and assign a
string to mood, a float to strength and an integer to rank. The
values you assigned can be anything as long as they are of
correct type.

Python_Introduction&DataType.pptx

  • 1.
  • 2.
    Overview Python is oneof the significant programming languages of the world. It is object oriented and an open source language. So everyone can learn python programming through a browser only rather than installing it in their operating language. It is considered as an easy to learn and maintainable language, so even kids can start learning python language. Python was introduced in 1991.It was named it after television show Monty Python’s Flying Circus.
  • 3.
    What is codingand why it is good for kids? •Everyone can learn to code. •It’s just like solving a puzzle or a riddle. •You apply logic, try a solution, experiment a little more, and then solve the problem. Good For Kids •Coding is fun. •Coding is a valuable job skill. Computer programming, or coding, is a crucial skill every child should be learning. We use computers to solve problems, play games, help us work more effectively, perform repetitive tasks, store and recall information, create something new, and connect with our friends and the world. Understanding how to code puts all this power at our fingertips.
  • 4.
    Why is pythonprogramming the best choice for kids to start programming? Python programming is an easy language and it has many other features which make it easy for kids to start learning programming. Following are the features of python programming for kids – 1.Easy Learning 2.Heavy Demand 3.Easy web development 4.Efficient for Machine learning and AI 5.Corporate friendly
  • 5.
    Why Python? •Python iseasy to understand, •Can be used in many different ways •Quick to learn. •Also, it is a popular language that runs on almost every machine and is used at many big, important organizations like Google, Instagram, NASA, and Spotify.
  • 6.
    Python features • Nocompiling or linking • Rapid development cycle • No type declarations • Simpler, shorter, more flexible • Automatic memory management • Garbage collection • High-level data types and operations
  • 7.
    Who Uses Python •Google • Amazon • NASA • ...the list goes on...
  • 8.
    Python structure • modules:Python source files or C extensions –import, top-level via from, reload • statements –control flow –create objects –indentation matters – instead of {} • objects –everything is an object –automatically reclaimed when no longer needed
  • 9.
    Python Interfaces •IDLE –a cross-platform Python development environment •Python Shell – running 'python' from the Command Line opens this interactive shell • Sublime editor •Notepad++ •Jupyter •Visual studio For the exercises, we'll use IDLE, but you can try them all and pick a favorite
  • 10.
    Python Installation If youare on a Windows machine, you probably don’t have Python installed already. This is because Windows operating systems don’t usually come with the Python language. That’s okay, though! We can get it ourselves. :) In Mac Python is already installed.
  • 11.
    1. On yourcomputer, open an Internet browser like Google Chrome or Mozilla Firefox. In the address bar, type https://www.python.org/downloads/ Python website’s 2. Download a newer version. Go ahead and click the DOWNLOAD button. 3. A download will start and will probably go to the bottom of your window like in the picture.
  • 12.
    4 Once yourdownload is complete, click on it to begin the installation. When you do, a window should pop up. 5. Go ahead and click the Run button.
  • 13.
    6 . Makesure to check the ADD PYTHON 3.7 TO PATH checkbox. 7. Click INSTALL NOW . Python should begin installing. You should see a window like this one: 8. Wait for the install to finish and the green bar to be full. Once it is done, the final screen should appear, saying that your installation was successful.
  • 14.
    IDLE – Development Environment •IDLEhelps you program in Python by: • color-coding your program code • debugging • auto-indent • interactive shell
  • 15.
    When you downloadand install Python, it will also install an application called IDLE. IDLE is short for Integrated Development and Learning Environment (that’s a mouthful!), and it is an integrated development environment, or IDE , that helps us with writing Python programs. To work in Python, you will need to open IDLE—opening Python files directly won’t work! Let’s take a look! 1. Click the Windows Start menu. 2 Start typing “idle”, then select the search result IDLE (Python 3.7 64-bit). Note: Yours might say IDLE (Python 3.7 32- bit) if that’s the kind of machine you have.
  • 16.
    3. A windowshould pop up that looks like this: 4. Awesome! You opened IDLE on Windows and are now ready to start writing some code in Python! : )
  • 17.
    Example Python •Hi Python print“Hi Python!” •Prints Hi Python! •Open IDLE and try it out yourself •Follow along using IDLE • Great job! You’ve written your first line of Python code! You’re about to learn some awesome things.
  • 18.
    Running & Savinga program • This is the best part—seeing your code in action! After you write some code, save it, and are ready to see it run. • Great job! You’ve written your first line of Python code! You’re about to learn some awesome things. • Go to the Run option on the menu above your program and select Run Module. This will run, or carry out, the instructions in your program. It will first ask you to save the program. Let’s call our file YourName.py. This tells your computer to save the program as a file called YourName.py, and the .py part means this is a Python program.
  • 19.
    More than justprinting •Python is an object oriented language •Practically everything can be treated as an object •“Hi Python” is a string •Strings, as objects, have methods that return the result of a function on the string
  • 20.
    Print Function •One ofthe most used lines of code in Python is the print() function. We use it everywhere. print("Hi Python!") •The print() function is used when we want to output a string. A string is a collection of characters, or what we know as text. Strings are a type —just like it sounds, a type is a way for the computer to understand what kind of input we are giving it. There are other types, like integers, Booleans, and lists •—but don’t worry about them yet! We’ll learn about them in next class. •The print() function takes a few parameters , which are pieces of information (input) you give a function to do something with. For now, we’ll only use one parameter, which is the part you put inside the double quotes. The print() function will take this piece and print it out to the console window.
  • 21.
    Comments Comments are piecesof code that do not get translated by the computer. You use them as helpful messages you leave for yourself within your code, or as parts of code you want the computer to ignore. You can create a comment by putting a hash character (#) before the line you’d like the computer to ignore. This is also called commenting out a line. As you’ll see, comments also become a noticeable red color to show you they are comments. # print("I should not be printed!") So, if there’s part of your code that you think is causing you problems, you don’t have to delete it. You can test it by commenting it out: print("Hello") # print("You are not working!") In the code above, it would print the first line (“Hello”), but not the second (“You are not working!”)—because the hash character signals to the computer, “Don’t print this line!” How cool is that?
  • 22.
    Python Overview • Programsare composed of modules • Modules contain statements • Statements contain expressions • Expressions create and process objects
  • 23.
    Day 1-Assignment 1 •Write something about yourself and save it with python extension and add comments where necessary.
  • 24.
    The World ofVariables • Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. • Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. • Variables are not declared, just assigned • The variable is created the first time, you assign it a value • Variables are references to objects • Everything in Python is an object
  • 25.
    Variable name –Identifiers Variable name is known as identifier. There are few rules that you have to follow while naming the variables in Python. 1. The name of the variable must always start with either a letter (a - z, A - B), or an underscore (_). For example: _str, str, num, _num are all valid name for the variables. 2. The name of the variable cannot start with a number. For example: 9num is not a valid variable name. 3. The name of the variable cannot have special characters such as %, $, # etc, they can only have alphanumeric characters and underscore (A to Z, a to z, 0-9 or _ ).
  • 26.
    4. Variable nameis case sensitive in Python which means num and NUM are two different variables in python. 5. In addition, there are some reserved words that you cannot use as variable name because they already have preassigned meanings in Python. These reserved words include words like print, input, if, while etc. We’ll learn about each of them in subsequent chapters.
  • 27.
    Variables example • Wheneveryou create a variable, you are allocating space in a computer’s memory, a storage that can hold values. Variables are given distinct names to identify their memory locations. These names are then used as a reference to instruct the computer to access, edit, save, or retrieve stored data. • Variable creation and management is a lot more flexible and straightforward in Python than in most other languages. You can easily create or declare a variable by using a syntactically appropriate name and assigning a value to it using the assignment operator (=). You need not even inform Python that you want a variable to contain a specific type of data. Python automatically identifies the data type based on the values you assign to the variable.
  • 28.
    Variables example • Theleft operands (in grey) are the names of the variables while the right operands (in blue) refer to the value assigned to • The left operands (in grey) are the names of the variables while the right operands (in blue) refer to the value assigned to the variable. The use of the assignment operator tells Python that a variable is assigned to store a particular value. Hence, in the assignment statement “average score = 80.50”, you are basically telling Python that the variable ‘average score’ is set to ‘80.50’. Python, in this case, knows that you are using the variable ‘average score’ to store a floating point number and there’s absolutely no need to declare that this variable is going to hold a float.
  • 29.
    •Multiple assignments inone statement •Python accepts multiple assignments in one statement with this syntax: •x, y, z = a, b,c •Assignment of a common value to several variables in a single statement •Python allows the assignment of a common value to several variables in a single statement with the syntax: •x = y = z = “apple”
  • 30.
    Memory Location To checkthe memory location of the variables, you’ll use the id() operator. Now you can type these assignments: >>>id(employee) >>>id(score) >>>id(counter) >>>id(comment) Once you type your assignments and press ENTER, Python will give you the memory location -
  • 31.
    Data Types inPython A data type defines the type of data, for example 123 is an integer data while “hello” is a String type of data. The data stored in memory can be of many types. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. The data types in Python are divided in two categories: 1. Immutable data types – Values cannot be changed. 2. Mutable data types – Values can be changed
  • 32.
    Data Types inPython Immutable data types in Python are: 1. Numbers 2. String 3. Tuple Mutable data types in Python are: 1. List 2. Dictionaries
  • 33.
    Python Numbers Python supportsintegers, floats and complex numbers. Number data types store numeric values. Number objects are created when you assign a value to them. For example − var1 = 1 var2 = 10 An integer is a number without decimal point for example 5, 6, 10 etc. A float is a number with decimal point for example 6.7, 6.0, 10.99 etc. A complex number has a real and imaginary part for example 7+8j, 8+11j etc.
  • 34.
    Python Numbers Python supportsfour different numerical types − ❑ int (signed integers) ❑ long (long integers, they can also be represented in octal and hexadecimal) ❑ float (floating point real values) ❑ complex (complex numbers) Examples Here are some examples of numbers − ❖ Python allows you to use a lowercase l with long, but it is recommended that you use only an uppercase L to avoid confusion with the number 1. Python displays long integers with an uppercase L. ❖ A complex number consists of an ordered pair of real floating-point numbers denoted by x + yj, where x and y are the real numbers and j is the imaginary unit.
  • 35.
    Integers (int) Integers arewhole numbers with no fractional parts and decimal point. They can be positive, negative, or zero. Integers can have unlimited size in Python 3 and are only limited by the available memory on your computer. Python supports normal integers as well as octal, hexadecimal, and binary literals: Examples: 44 4500 -32 0 96784502850283491 # Python program to display numbers of # integer data type # int num1 = 10 num2 = 100 print(num1+num2) Output: 110
  • 36.
    Floating-Point Numbers (Floats) Floating-pointnumbers are real numbers with a decimal point. Examples: 0.50, 42.50 10500.40 2.5 # Python program to display numbers of # float data type # float a = 10.5 b = 8.9 print(a-b) Output: 1.5999999999999996
  • 37.
    Complex Numbers Complex numbersare pairs of real and imaginary numbers. It takes the form ‘a + bJ’ or ‘a + bj’ where the left operand is a real number while the right operand is a float (b) and an imaginary number (J). The upper or lower case letter Jj refers to the square root of -1, an imaginary number. Example: >>> abc = 2 + 4j >>> xyz = 1 - 2j >>> abcxyz = abc + xyz >>>print(abcxyz) (3+2j)
  • 38.
    Variable & DataType- Assignment 2 1. Write a program to assign a value to variable and print its value 2. Write a program to assign multiple values and print. 3. Create three variables mood, strength and rank and assign a string to mood, a float to strength and an integer to rank. The values you assigned can be anything as long as they are of correct type.