Automation With Pycharm Python Interview Question And Answers

4 Write a Code to Sort an Array in Numpy by the (N-1)Th Column.

This can be achieved by using argsort() function. Let us take an array X; the code to sort the (n-1)th column will be x[x [: n-2].argsoft()]

The code is as shown below:



8 Explain join() and split() functions in Python.

The join() function can be used to combine a list of strings based on a delimiter into a single string.

The split() function can be used to split a string into a list of strings based on a delimiter.

string = “This is a string.”

string_list = string.split( ) #delimiter is ‘space’ character or ‘ ‘

print(string_list) #output: [This, is, a, string.]

print( .join(string_list)) #output: This is a string.

  • The function definition uses the *args syntax to pass variable-length parameters.
  • “*” denotes variable length, while “args” is the standard name. Any other will suffice.
  • **kwargs is a special syntax for passing variable-length keyworded arguments to functions.
  • When a variable is passed to a function, it is called a keyworded argument.
  • “Kwargs” is also used by convention here. You are free to use any other name.
  • 3 How Do You Get Indices of N Maximum Values in a Numpy Array?

    >>print(arr.argsort( ) [ -N: ][: : -1])

    10 How multithreading is achieved in Python?

  • Although Python includes a multi-threading module, it is usually not a good idea to utilize it if you want to multi-thread to speed up your code.
  • As this happens so quickly, it may appear to the human eye that your threads are running in parallel, but they are actually sharing the same CPU core.
  • The Global Interpreter Lock is a Python concept (GIL). Only one of your threads can execute at a moment, thanks to the GIL. A thread obtains the GIL, performs some work, and then passes the GIL to the following thread.
  • 5 Write a program to count the number of capital letters in a file?


    Q8 Explain how you can set up the Database in Django.

    Ans: You can use the command edit mysite/, it is a normal python module with module level representing Django settings.

    Django uses SQLite by default; it is easy for Django users as such it won’t require any other type of installation. In the case your database choice is different that you have to the following keys in the DATABASE ‘default’ item to match your database connection settings.

  • Engines: you can change the database by using ‘django.db.backends.sqlite3’ , ‘django.db.backeneds.mysql’, ‘django.db.backends.postgresql_psycopg2’, ‘’ and so on
  • Name: The name of your database. In the case if you are using SQLite as your database, in that case, database will be a file on your computer, Name should be a full absolute path, including the file name of that file.
  • If you are not choosing SQLite as your database then settings like Password, Host, User, etc. must be added.
  • Django uses SQLite as a default database, it stores data as a single file in the filesystem. If you do have a database server—PostgreSQL, MySQL, Oracle, MSSQL—and want to use it rather than SQLite, then use your database’s administration tools to create a new database for your Django project. Either way, with your (empty) database in place, all that remains is to tell Django how to use it. This is where your project’s file comes in.

    We will add the following lines of code to the file:

    Q3 What are the generators in python?

    Ans: Functions that return an iterable set of items are called generators.

    Python Real Time Interview Questions & Answers Part-1

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *