Explain identity operators in Python.
This is one of the very commonly asked Python Interview Questions and answers it with examples.
The operators ‘is’ and ‘is not’ tell us if two values have the same identity.
>>> 10 is '10'
False
>>> True is not False
True
Finally, tell us about bitwise operators in Python.
These operate on values bit by bit.
1. AND (&) This performs & on each bit pair.
>>> 0b110 & 0b010
2
2. OR (|) This performs | on each bit pair.
>>> 3|2
3
3. XOR (^) This performs an exclusive-OR operation on each bit pair.
>>> 3^2
1
4. Binary One’s Complement (~) This returns the one’s complement of a value.
>>> ~2
-3
5. Binary Left-Shift (<<) This shifts the bits to the left by the specified amount.
>>> 1<<2
4
Here, 001 was shifted to the left by two places to get 100, which is binary for 4.
6. Binary Right-Shift (>>)
>>> 4>>2
1
How would you work with numbers other than those in the decimal number system?
With Python, it is possible to type numbers in binary, octal, and hexadecimal.
1. Binary numbers are made of 0 and 1. To type in binary, we use the prefix 0b or 0B.
>>> int(0b1010)
10
To convert a number into its binary form, we use bin().
>>> bin(0xf)
‘0b1111’
2. Octal numbers may have digits from 0 to 7. We use the prefix 0o or 0O.
>>> oct(8)
‘0o10’
3. Hexadecimal numbers may have digits from 0 to 15. We use the prefix 0x or 0X.
>>> hex(16)
‘0x10’
>>> hex(15)
‘0xf’
Why are identifier names with a leading underscore disparaged?
Since Python does not have a concept of private variables, it is a convention to use leading underscores to declare a variable private. This is why we mustn’t do that to variables we do not want to make private.
How can you declare multiple assignments in one statement?
There are two ways to do this:
>>> a,b,c=3,4,5 #This assigns 3, 4, and 5 to a, b, and c respectively
>>> a=b=c=3 #This assigns 3 to a, b, and c
What is tuple unpacking?
First, let’s discuss tuple packing. It is a way to pack a set of values into a tuple.
>>> mytuple=3,4,5
>>> mytuple
(3, 4, 5)
This packs 3, 4, and 5 into mytuple.
Now, we will unpack the values from the tuple into variables x, y, and z.
>>> x,y,z=mytuple
>>> x+y+z
12
What is Object Oriented model?
This model is based on the collection of objects. An object contains values stored in instance variables within the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain the same types of values and the same methods are grouped together into classes.
What is E-R model?
This data model is based on real-world that consists of basic objects called entities and of the relationship among these objects. Entities are described in a database by a set of attributes.
What is RDBMS?
RDBMS stands for Relational Database Management Systems. It is used to maintain the data records and indices in tables. RDBMS is the form of DBMS which uses the structure to identify and access data concerning the other piece of data in the database. RDBMS is the system that enables you to perform different operations such as- update, insert, delete, manipulate and administer a relational database with minimal difficulties. Most of the time RDBMS use SQL language because it is easily understandable and is used for often.
What is Data Model?
The Data model is specified as a collection of conceptual tools for describing data, data relationships, data semantics and constraints. These models are used to describe the relationship between the entities and their attributes.
There is a number of data models:
-
Hierarchical data model
-
network model
-
relational model
-
Entity-Relationship model and so on.
.png)