Python For All Notes
Python For All Notes
What is python?
Python IDLE
Software Development.
Naming variables in Python
There are rules in Python about naming variables. A variable name must:
In Python
Variable=value
The following Python command will get user input and store it as a variable
called name:
The text inside the brackets is called the prompt. The prompt tells the user what
to input.
To produce output in Python you use the command print. After this command
you insert brackets. Whatever you put inside the brackets will be output.
e-g -password=”diamond7”
print(“hello”)
print(name)
Python shell does not save the commands. If you want to use the same
commands again, you have to type them again.
Create a file
In the Python shell, open the ‘File’ menu Choose ‘New file’. Now there are
two open windows. One is the interactive window (python shell). The other
is the editor window (file window). The file window is empty.
When you write code in a Python file, you don’t need to include the >>>
prompt. Before you run your program, you need to save it. Select File Save
from the menu and save the file as hello_world.py.
You can type code into both the interactive window and the editor window.
The difference between the two windows is in how they execute code. In
this section, you’ll learn how to execute Python code in both windows.
Python hello.py
The software that you use to write and run programs is called an IDE. That
stands for IDE. An IDE lets you enter and save program commands. It displays
error messages. It runs the program. It lets the user enter the input and it shows
the output.
The IDE you are using to make Python programs is called IDLE. It is simple
text-based software. The program output is shown in the python shell.
Python examples
Q- print("Hello World")
Q-print('Python is powerful')
Output:
Python is powerful
Q-print('Good Morning!')
Output
Good Morning!
It is rainy today
Enter a number: 10
You Entered: 10
Q-If you want to print the name of five countries, you can write:
print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")
Let see an example. We will define variable in Python and declare it as “a” and
print it.
a=100
print (a)
Ans-100
x=3
y = 3∗ x
print(y)
Ans:9
a=2
b=5
x=3
y = a ∗x + b
print(y)
Ans:11
In computer programming, data types specify the type of data that can be stored
inside a variable. For example,
num = 24
Here, 24 (an integer) is assigned to the num variable. So the data type of num is
of the int class.
num1 = 1.5
num2 = 6.3
name = 'Python'
print(name)
print(message)
Output
Python
Area=width*length
Volume=Area*depth
Width=10-meters
Length=15-meters
Depth=1.5-maters