Basics of Python Programming Part — 1 | Python Tutorial
In general, the Standard way to save and run a python program is as follows:
- Open an editor.
- Write the instructions.
- Save it as a file with the filename having the extension.py.
- Run the interpreter with the command python program_name.py or use IDLE to run the program.
On very first open your editor
Now, Open a new file in Editor by File > New File.
After opening a New File Write your code and Save it by File > Save
Now save the with the filename. extension Ex — Hello.py
Now, run your program through the Run > Run Module
So, This is the basic information about how to open an editor and create a new file after that writing your code on the new file and then save the file with .py extension and run your program.
Literal Constant
The word ‘literal’ has been derived from literally. The Literal constant value is used directly in the program. Moreover, it is constant so its value will never be changed. means 4 always represents itself and nothing else.
Some more Literal constants are — 7, 4.7, ‘ram’, “Shyam”, etc.
Here we are just learning Number constant and String Constant. We will give you a brief knowledge about them.
Numbers Constant — This constant refers to a numeric value. You can use three types of numbers in the python program.
String Constant — A string is nothing but a group of characters. You can use string in different ways in the python program.
Using single quotes (‘ ‘): A string can be written as ‘HELLO WORLD’
Using double quotes(“ “): The result of single quotes string and double quotes string will be the same means ‘HELLO’ and “HELLO” both are the same.
Variable and Identifier
Variable is used to store the data of literal constant. In simple language, we can say that variable means whose values are varied. There are certain rules for declaring or creating a variable -
- The first character of an identifier must be an alphabet or underscore(_).
- A variable name only consists of digit, alphabet or underscore and nothing else.
- The Variable name are case sensitive means ‘theBook’ and ‘TheBook’ both are different variable.
- Punctuation characters such as $, @, # are not allowed within Identifiers.
Some Examples of Valid Identifiers
a, add, Add_of_two, sub122, etc
Some Example of Invalid Identifiers
23js, ty@ty, ram Kumar, etc.
Data Type
The value that stores in variable has a type, called Data Type. There are different data types available in python for stores different types of values. Based on the data type of variable, the interpreter reserve memory for it and also determined the type of data that can be stored in the reserved memory.
The five standard data types supported by python are -
- String
- List
- Tuple
- Dictionaries
- Numbers
How to Initialize values to a Variable?
# Program to display data of different types using variables and Literals
num = 7
amt = 123.45
code = ‘A’
pi = 3.1415945637
msg =”Hello”
This is the way we can store literals in variables. As we can see above an example “ num = 7”. Here, ‘num’ is a variable and ‘7’ is Literal. Now we can change the value of variable ‘num’ like we can put another number instead of 7 and the value of num is changed.
Now, we are going to learn how we take input from user in python programming language. In python, there is a function available for taking input from the user name ‘input ()’ function.
The most important thing to remember is input () function takes the value from the user as a String. so, whether you entered a number or string it is treated as a string only.
- name = input(“What is your name?”)
- age = input(“What is your age?”)
Now, both the variable ‘name’ and ‘age’ contains only string literals.
Originally published at https://techsamajho.blogspot.com.