How to Run python in the integrated development environment (IDE)
You can use any text editing software to write a Python script file.
We just need to save it with the .py extension. But using an IDE will make your coding easier.
By the way, when you have installed Python, an IDE named IDLE is also installed. You can use it to run Python codes on your computer.
It's an easy platform for beginners.
When you open Python IDLE, an interactive Python shell is opened.
Here, you can use it as a calculator 🖩
1+12+5
print("Learn from ur mistakes")
Do any code of your own.
Press Ctrl+N to open a new file
Let's start
My first program
print("Hello coders!! ")
print("It's my first program ")
Save this file in your separate folder, so that you can access it later(It's a good habit to organize your files.).
File > Save as > Choose your destinaton
Save your file with .py extension, example first_program.py
How to run?
When your file is saved
Either you can go to > Run > Run Module or simply press F5.
Python Keywords and Identifiers:
Keywords:
Keywords are the reserved words in Python.
★ We cannot use a keyword as a variable name, function name, or any other identifier.
★ Keywords are case sensitive.
★ There are 33 keywords in python 3.7. (This number may vary )
Identifiers:
An Identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.
Can I use any characters to name my identifiers?
No. Like most other programming languages, Python has some rules that must be followed when you create names.
Rules for writing identifiers
1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase or uppercase(A to Z) or digits (0 to 9) or an underscore (_).
Example: Selection_Sort, var_1, etc. are valid.
2. An identifier cannot start with a digit.
Example: 1var is not valid but var1 or var_1 are valid.
3. Keywords cannot be used as identifiers
4. We cannot use special symbols like !,@,#,*,&,^,%,$, etc. in our identifiers.
Example: X@ = 20 is not valid.
5. An identifier can be of any length but it's good when it is easy to understand and according to your code.
Example: members, time, name,
Yes, good naming practice is always important. 🙋 But what about case sensitivity?
Yes, Python is the “sensitive type,” in that Python code is case sensitive. This means that "Hi" and "hi" are two different names, so be careful.
For instance, you can use an identifier in your code only if it has been given a value; unassigned identifiers cause a runtime error.
Python Variables, constants, and literals
Python Variables
A variable is named location used to store data in the memory.
Example: number = 50
Constant
A constant is a type of variable whose value cannot be changed.
Example: pi = 3.14
Gravity= 9.8
Literals
Literals are raw data given in a variable or constant.
★ Numeric literals
a) float
b) Integer
c) complex
★ String Literals
It is a sequence of characters surrounded by quotes.
★Boolean Literals
a) True
b) False
Python Data types
Python numbers
1. Integer
2.Float
3. Complex
You can use type() function to check the data type of your variable
a=10
print(type(a))
b=10.0
print(type(b))
c= 1+2j
print(type(c))
Python list
★ List is an ordered sequence of items.
★ All the items in the list need not to be of same type.
★ It is very flexible and mostly used datatype.
Example: a=[1,3.8,python]
Python Tuple
★Tuple is an ordered sequence of item the same as list.
★ They are immutable.
★ Tuples once created cannot be destroyed.
★ They are usually faster than list as they cannot changed dynamically.
Example: t=(1,3.8,python)
Python Strings
★ The string is a sequence of Unicode characters.
★ We can use single or double quotes to represent them.
★ Multi-line strings are denoted using triple ' ' ' or " " "
Python Dictionary
★ Dictionary is an unordered collection of key-value pairs.
★ Dictionaries are denoted by braces {} with a key and value pair key: value.
So helpful
ReplyDeletePost a Comment