Python Interview Answers

3 min
7
0
0
Published on updated on
  1. What is Python?
    Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2.
  2. Is there a tool to help find bugs or perform static analysis?
    Yes. PyChecker is a static analysis tool that finds bugs in Python source code and warns about code complexity and style.
  3. What are the rules for local and global variables in Python?
    In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function's body, it's assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as 'global'.
  4. How can I find the methods or attributes of an object?
    For an instance x of a user-defined class, dir(x) returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class.
  5. Is there an equivalent of C's "?:" ternary operator?
    No.
  6. How do I convert a number to a string?
    To convert, e.g., the number 144 to the string '144', use the built-in function str(). If you want a hexadecimal or octal representation, use the built-in functions hex() or oct().
  7. What's a negative index?
    Python sequences are indexed with positive numbers and negative numbers. For positive numbers 0 is the first index 1 is the second index and so forth. For negative indices -1 is the last index and -2 is the penultimate index and so forth. Think of seq[-n] as the same as seq[len(seq)-n].
    Using negative indices can be very convenient. For example S[:-1] is all of the string except for its last character, which is useful for removing the trailing newline from a string.
  8. What is a method?
    A method is a function on some object x that you normally call as x.name(arguments...). Methods are defined as functions inside the class definition:
    class C:
    def meth (self, arg):
    return arg*2 + self.attribute
  9. What is self?
    Self is merely a conventional name for the first argument of a method. A method defined as meth(self, a, b, c) should be called as x.meth(a, b, c) for some instance x of the class in which the definition occurs; the called method will think it is called as meth(x, a, b, c).
  10. How do I delete a file?
    Use os.remove(filename) or os.unlink(filename);
  11. How do I copy a file?
    The shutil module contains a copyfile() function.
  12. Can I create my own functions in C?
    Yes, you can create built-in modules containing functions, variables, exceptions and even new types in C.

 

Continue reading around the topics :

Comment

In the same category

The best IT jobs for introverts IT Career Advice
Introverts can thrive in IT jobs that require focus, problem-solving, and independent work. There are plenty of roles perfect for those who prefer working behind the scenes.
4 min
data jobs in the UK IT Career Advice
Data jobs in the UK are in high demand, with roles in data science, engineering, and analysis offering excellent career stability. From junior data analysts to senior roles like chief data officer, these positions provide clear growth opportunities with salaries ranging from £25,000 to £100,000+
3 min
Preparing for your Junior Data Analyst interview IT Career Advice
Interviews for a Junior Data Analyst role can be challenging, but preparation is key. Be ready to discuss tools like Excel, SQL, and Python, and share how you've used them in projects. This guide covers key questions and tips to help you feel confident.
4 min

Connecting Tech-Talent

Free-Work, THE platform for all IT professionals.

Free-workers
Resources
About
Recruiters area
2024 © Free-Work / AGSI SAS
Follow us