Coder Social home page Coder Social logo

pythonquestionsandanswers's Introduction

"PYTHON = (P)rogrammers (Y)earning (T)o (H)omestead (O)ur (N)oosphere."

━ Sean McGrath     

Python Interview Questions and Answers


Table of Contents

Questions
1 What is the built-in function used in Python to iterate over a sequence of numbers?
2 Suppose list1 is [2, 12, 222, 55, 52]. What is list1[-1]?
3 Explain the //, %, and ** operators in Python.
4 Explain logical operators in Python.
5 How do you calculate the length of a string?
6 How will you remove last object from a list?
7 How will you capitalize the first letter of a string?

  1. What is the built-in function used in Python to iterate over a sequence of numbers?

    Pythonda range() funksiyası ədədlər ardıcıllığını qaytarır və default olaraq 0-dan başlayır, 1-1 artır və müəyyən edilmiş ədəddən sonra dayanır.

    Sintaksisi bu şəkildədir:

    range(start, stop, step)
    

    Nümunə:

    for n in range(5, 12):
      print (n)

    Bu zaman ardıcıllıq 5-dən başlayıb (5 də daxil olmaqla) 12-yə qədər (12 daxil deyil) davam edəcək.

    Çıxış:

    5
    6
    7
    8
    9
    10
    11
    

    Başqa bir nümunəyə baxaq:

    for i in range(2, 15, 3):
      print (i)

    Ardıcıllıq 2-dən başlayıb 15-ə qədər 3-3 artaraq davam edəcək.

    Çıxış:

    2
    5
    8
    11
    14
    

  1. Suppose list1 is [2, 12, 222, 55, 52]. What is list1[-1]?

    Ədəd mənfi (sondan başlayacaq) və 1 (1-ci ədədi götürəcək) olduğu üçün cavab 52 olacaq.


  1. Explain the //, %, and ** operators in Python.

    // operatoru qalıqsız bölmə operatorudur. Nəticə həmişə tam ədəd olur.

    Nümunə:

    55 // 10

    5 qaytaracaq, çünki 55-in içində 5 dənə 10 var. Qalıq isə nəzərə alınmır. Əgər adi bölmə əməliyyatı (55 / 10) ilə yazsaydıq cavab 5.5 olardı.


    ** operatoru qüvvətə yüksəltmə operatorudur.

    Nümunə:

    5 ** 2

    25 qaytaracaq, çünki 5-i 2 dəfə öz-özünə vuranda (5 üstü 2) 25 edir.


    % operatorunun mənası budur ki, məsələn, a b-yə bölünür və onların bölünməsindən qalıq c alınır. Buradakı qalıq c a % b ifadəsinin cavabıdır.

    Nümunə:

    50 % 12

    2 qaytaracaq, çünki 50 12-yə bölünür və cavab 4 (qalıq 2) olur. Qalıq 2 olduğu üçün də cavab 2 olacaq.


  1. Explain logical operators in Python.

    Məntiqi operatorlar şərti ifadələrdə istifadə olunur və boolean dəyər (True və ya False) qaytarır. Pythonda 3 məntiqi operator var.

    Operator Təsviri Sintaksisi
    and Əgər hər iki tərəf doğrudursa True qaytarır a and b
    or Əgər iki tərəfdən biri doğrudursa True qaytarır a or b
    not Nəticəni tərsinə çevirir, əgər doğrudursa False qaytarır, yanlışdırsa True qaytarır not a

    Nümunə:

    a = 5
    
    print(5 >= a and 20 > a) # True qaytarır, çünki şərtlərin hər ikisi də doğrudur
    
    print(5 < a or 20 > a) # True qaytarır, çünki şərtlərdən biri doğrudur
    
    print(not(5 < a or 20 > a)) # False qaytarır, çünki nəticə tərsinə çevrilir

    Belə bir cədvəllə sualı yekunlaşdıraq.

    Operator A Operator B Logical AND nəticə
    True True True
    True False False
    False True False
    False False False
    Operator A Operator B Logical OR nəticə
    True True True
    True False True
    False True True
    False False False
    Operator A Logical NOT nəticə
    True False
    False True

  2. How do you calculate the length of a string?

    Bunun üçün len() funksiyasından istifadə edirik və stringlərin uzunluğunu hesabladığımız üçün nəticə olaraq xarakterlərin sayını qaytarır.

    Nümunə:

    s = len("mətn")
    print(s) # 4 qaytarır
    
    a = len("Salam, Zöhrab!")
    print(a) # 14 qaytarır

  3. How will you remove last object from a list?

    Bunun üçün pop() metodundan istifadə edə bilərik.

    Sintaksisi:

    list.pop(mövqe)
    

    Nümunə:

    meyveler = ["armud", "alma", "banan"]
    
    print(meyveler) # ['armud', 'alma', 'banan']
    
    meyveler.pop()
    print(meyveler) # ['armud', 'alma']
  4. How will you capitalize the first letter of a string?

    Bunun üçün capitalize() metodundan istifadə edə bilərik. Capitalize() metodu ilk xarakterin böyük, qalanlarının isə kiçik hərf olduğu stringi qaytarır.

    Sintaksisi:

    string.capitalize()
    

    Nümunə:

    str = "gör məni!"
    
    c = str.capitalize()
    
    print (c) # Gör məni!

    Sualları bu repodan götürmüşəm.

pythonquestionsandanswers's People

Contributors

isbendiyarovanezrin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.