Basics - Python Developer Interview

Basics - Python Developer Interview

Part1

Cover Photo by Bonneval Sebastien on Unsplash

Welcome to the series of 'Important concepts for Python Developer interview'. Let's start with basics we need to cover for interview.

Below are the topics we are going to cover in this article:

  • Variables

  • Operators

  • Data types

  • Common methods used with data types

What are variables?

  • Variables are nothing but a container to contain that particular value

  • Value can be of any type for example, int, float, string. There is no need to specify the type of variable while assigning the value. Python is intelligent enough to infer the type of variable based on assigned value.

  • Variables cannot start with number or any special character like #,&,%,*.

  • Variable names are only allowed to have alphanumeric characters and underscore.

  • Examples of variable name: _allowedname, Valid, temp1

What are operators?

Operators are the symbols which perform some operations. Below are the different type of operators in Python:

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators
  6. Identity Operators

Arithmetic Operators:

These operators perform arithmetic operations

Screenshot 2021-03-21 at 12.11.14 PM.png

Comparison Operators: image.png

Logical Operators:

image.png

Bitwise Operators: These operators are used to do the operations on binary numbers

image.png

Assignment Operators:

image.png

Identity Operators:

It is actually used to check if provided objects are actually same object with same memory location. It is possible that two different objects have same value but they can't have same location.

image.png

What are data types present in Python?

  1. Numbers(Numeric)
  2. String
  3. List
  4. Tuple
  5. Dictionary
  6. Boolean
  7. Set

Numbers:

  • Numbers that is numeric data type.

  • It again have different types like int, float, complex, long. We can also use functions int(), long(), float(), complex() to convert data from one type to another. For example: 7(int), 3490L(long), 90.23(float), 87.2J(complex)

String:

  • Enclosed in either single quotes(' ') or double quotes(" ")

  • Python can use a special syntax to format multiple strings and numbers. Please refer link for more information on formatting the string.

  • Examples: 'Hello World!', "Valid string"

List

  • A list can contain ordered series of values. There is no restriction on which values it can contain that means you can include values of different data types in list.
  • It is enclosed in [ ] and first element has 0 index value in list.
  • Example: [1, "cool", [3.14, 7.8]]

Tuple

  • It is the group of values like list but it has fixed group of values that means we cannot modify Tuple after assigning the values.

  • It is enclosed in ( )

  • We cannot append, extend, remove elements from Tuple, we can only access them. Tuple is immutable data type.

  • Example: food = ("rice", "bread", "eggs")

Dictionary

  • It is group of key:value pairs

  • These are unordered, iterable and mutable.

  • Example: { "Maharashtra" : "Mumbai", "Karnataka": "Bengaluru", "Tamilnadu":"Chennai"}

Boolean:

This data type have only two values 'True' and 'False'. It is used to represent truth value of expression.

'True' and 'False' are keywords.

Set:

  • Set is an unordered collection of data type that is iterable, mutable and has no duplicate elements.

  • Example: ("noRepeatValue", "nonRepeatValue")

Below is the classification of all the data types as Mutable VS Immutable

Mutable : Able to modify

Immutable : Not able to modify

image.png

Common methods used with data types:

Common methods of Strings

  • capitalize() : Converts first character to Capital Letter

  • join() : Returns a Concatenated String

  • lower() : Returns lowercased string

  • upper() : Returns uppercased string

  • index() : Returns Index of Substring

  • isdigit() : Checks Digit Characters

  • swapcase() : swap uppercase characters to lowercase; vice versa

  • strip() : Removes Both Leading and Trailing Characters

Common methods of List

  • append() : Add a single element to the end of the list

  • reverse() : reverses the list

  • sort() : Sorts the list

  • insert() : insert an element to the list

  • count() : returns count of the element in the list

Common methods of Dictionary:

  • keys() : Returns list of all keys in Dictionary

  • items() : Returns list of key, value pair inside Dictionary

  • get() : Returns Value of The Key

These are some of the commonly used methods with above data types.

We have covered the decided topics, for next article stay tuned!