Introduction
Python is an interpreted, high-level, and general-purpose programming language. from a beginner's perspective python is the best choice to start.
The Best Advantage of using an interpreted language is that they are platform-independent.
In Python, Instead of translating the code into Machine Code, The Code is translated into bytecode.
Byte Code Is a low-level set of instructions that can be executed by an interpreter. It is executed on virtual memory.
The Source Code of Python is compiled into byte code, and then with the help of Python Virtual Memory, it is again converted into machine code that the computer can understand.
Python Installation
Open the below link to download Python for Windows
Installation completed.
Python Programming Getting Started
1. Open IDLE (Python Editor)
Python Variables
Variables are containers for storing data values
Python has no command for declaring a variable.
Variable names must begin with a letter or an underscore, but they can be a group of both letters and digits.
Variable names are case-sensitive.
String variables can be declared either by using single or double quotes
Let's see the sample example programs about variables.
In the above example variable 'a' contains the value of 10 (integer data type), and variable 'b' contains the value of 14 (integer data type), we print the addition operation using the variable '(a+b)' and it provides output as 24.
let's make some changes in the above code
in the above example variables 'a & b' contain the values as (String data type - it's denoted under double quotes ) not as an integer data type
so it does not perform addition operations with string values.
in the above example variable 'a' contains the value of Gokul (string data type), we print variable 'a' and it provides output as Gokul.
Type Casting
If you want to specify the data type of a variable, this can be done with casting.
in the above example variables 'a & b' we added integer values under string type with double quotes and we denoted values with 'int' (Integer) which will convert the string values into Integer.
Get the Type
we can get the data type of a variable with the type()
function.
in the above example we tried to print the type of the variables 'a', and it printed the output as variable 'a' type class as int (Integer).
in the above example we tried to print the type of the variables 'a', and it printed the output as variable 'a' type class as str (String).
User Input and casting
in the above example, we tried to get the values of the variables 'a&b' from the user using an Input function. based on user input (a=15 & b=20) it prints the output of (a+b) (35).
in the above example, we tried to get the values of the variables 'name & age' from the user using an Input function. based on user input it will print the output with the string as we mentioned ("My Name is: " & "My Age is: ").
Let's do some practice Program
Congrats🎉, On Learning The Basics of Python.
Happy Learning :)