Posts

Showing posts from January, 2020

Print,Input syntax in python and Examples

input(): In python it is used to assign data for variables it is like scanf in c a=input()  print(a) Output: >>>5 >>>'5' It will take input as string by default To take it as integer we want to convert string to integer (explict function) For Example: a=int(input()) print(a) Output: >>>5 >>>5 In python 3x input syntax will be :                                                               input() In python 3x input syntax will be :                                                               1.raw_input()                                ...

To print python keywords in a list

import keyword print(keyword.kwlist) Output: ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] to print length of keywords: import keyword print(len(keyword.kwlist)) Output:  35 There will be different number of keywords in python based on python version Python : 2x version : 31 keywords Python : 3x version upto 3.5 : 33 keywords from python 3.6 to : 35 keywords are available

What is difference between compiler and interpreter?

Compiler: It is a software program is used to convert source code or human language code into machine code or low-level language. By using compiler, overall program is compiled and if there is any error in program it is difficult to correct. Intrepreter:  It is a software program is used to convert source code or human language code into machine code or low-level language. Main difference between compiler and interpreter: An interpreter translates high-level instructions into an intermediate form , which it then executes. In contrast, a  compiler  translates high-level instructions directly into  machine language . Compiled programs generally run faster than interpreted programs. The advantage of an interpreter, however, is that it does not need to go through the compilation stage during which machine instructions are generated. This process can be time-consuming if the program is long. The interpreter, on the other hand, can immediately execute high-level ...

Why Python is pretty easy when compared to other languages?

1.Easy syntax For example to add two numbers in c: #include<stdio.h> void main() { int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); } Same example in python: a,b=eval(input("enter a,b values")) print(a+b) So it is pretty easy to write code in python. If you are beginner to write a code then python is good to learn. 2.Scripting programming language In above example, we seen that we have declared what data type it is before a,b variables we have to specify which data type it belongs to? But in python when we give input suppose:                                                                        a=10 10 is an integer no need to mention what datatype it is like int,float,char,string... By default it will treat as string only.