PYTHON INTERVIEW QUESTIONS
WHAT IS PYTHON?
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it h
as fewer syntactical constructions than other languages.
as fewer syntactical constructions than other languages.
WHAT ARE THE SUPPORTED DATA TYPES IN PYTHON?
Python has five standard data types:
- Numbers
- String
- List
- Tuple
- Dictionary
WHAT IS TUPLES IN PYTHON?
A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.
WHAT IS THE DIFFERENCE BETWEEN TUPLES AND LISTS IN PYTHON?
The main differences between lists and tuples are − Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as read-only lists.
WHAT ARE PYTHON'S DICTIONARIES?
Python’s dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.
NAME SOME OF THE FEATURES OF PYTHON?
Following are some of the salient features of python −
- It supports functional and structured programming methods as well as OOP.
- It can be used as a scripting language or can be compiled to byte-code for building large applications.
- It provides very high-level dynamic data types and supports dynamic type checking.
- It supports automatic garbage collection.
- It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
HOW WILL YOU CREATE A DICTIONARY IN PYTHON?
Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).
dict = {}
dict[‘one’] = “This is one”
dict[2] = “This is two”
tinydict = {‘name’: ‘john’,’code’:6734, ‘dept’: ‘sales’}
dict = {}
dict[‘one’] = “This is one”
dict[2] = “This is two”
tinydict = {‘name’: ‘john’,’code’:6734, ‘dept’: ‘sales’}
WHAT IS PYTHON REALLY? YOU CAN (AND ARE ENCOURAGED) MAKE COMPARISONS TO OTHER TECHNOLOGIES IN YOUR ANSWER
Here are a few key points:
- Python is an interpreted language. That means that, unlike languages like Cand its variants, Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby.
- Python is dynamically typed, this means that you don’t need to state the types of variables when you declare them or anything like that. You can do things like x=111and then x=”I’m a string”without error
- Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++’s public, private), the justification for this point is given as “we are all adults here”
- In Python, functions are first-class objects. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects
- Writing Python code is quick but running it is often slower than compiled languages. Fortunately, Python allows the inclusion of C based extensions so bottlenecks can be optimised away and often are. The numpypackage is a good example of this, it’s really quite quick because a lot of the number crunching it does isn’t actually done by Python
- Python finds use in many spheres – web applications, automation, scientific modelling, big data applications and many more. It’s also often used as “glue” code to get other languages and components to play nice.
- Python makes difficult things easy so programmers can focus on overriding algorithms and structures rather than nitty-gritty low level details.
WHY IS IT CALLED PYTHON?
When he began implementing Python, Guido van Rossum was also reading the published scripts from “Monty Python’s Flying Circus”, a BBC comedy series from the 1970s. Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python.
WHAT IS THE INTERPRETER IN PYTHON?
An interpreter is a program that reads and executes code. This includes source code, pre-compiled code, and scripts. Common interpreters include Perl, Python, and Ruby interpreters, which execute Perl, Python, and Ruby code respectively.
WHAT DOES A PYTHON DO?
Python is a general-purpose programming language typically used for web development. … SQLite is one free lightweight database commonly used by Pythonprogrammers to store data. Many highly trafficked websites, such as YouTube, are created using Python.
DESCRIBE PYTHON'S GARBAGE COLLECTION MECHANISM IN BRIEF.
A lot can be said here. There are a few main points that you should mention:
- Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the associated object is no longer live and the memory allocated to that object can be freed up for something else
- occasionally things called “reference cycles” happen. The garbage collector periodically looks for these and cleans them up. An example would be if you have two objects o1and o2 such that x == o2 and o2.x == o1. If o1 and o2 are not referenced by anything else then they shouldn’t be live. But each of them has a reference count of 1.
- Certain heuristics are used to speed up garbage collection. For example, recently created objects are more likely to be dead. As objects are created, the garbage collector assigns them to generations. Each object gets one generation, and younger generations are dealt with first.
This explanation is CPython specific.
WHAT IS THE OUTPUT OF PRINT STR IF STR = 'HELLO WORLD!'?
It will print complete string. Output would be Hello World!.
WHAT IS THE OUTPUT OF PRINT STR`{`0`}` IF STR = 'HELLO WORLD!'?
It will print first character of the string. Output would be H.
Great and useful blog.
ReplyDeletePython Training course | Python Training Chennai
Usually, I never comment on blogs but yours is so convincing that I never stop myself to say something about it. keep updating regularly.
ReplyDeleteBest IELTS Classes in Mulund
IELTS Centres in Mulund East
IELTS Coaching Classes in Mulund
IELTS Training in Mulund
IELTS Coaching Centres in Mulund
Best IELTS Course in Mulund West
IELTS Training Institute near me