1. Home
  2. Explore
  3. Computer Science
  4. Python Programming Tutorial

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python Programming Tutorial

  • 75Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python Foundations
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is Python, and who created it?

Tap to flipClick to flipspace

Python is a general-purpose, high-level, interpreted, dynamically typed programming language created by Guido van Rossum.

Or swipe the card

75 cards

  1. What is Python, and who created it?

    Python is a general-purpose, high-level, interpreted, dynamically typed programming language created by Guido van Rossum.

  2. What does it mean that Python is a general-purpose language?

    It can be used to write software in many application domains rather than being restricted to one field.

  3. What does it mean that Python is a high-level language?

    Its syntax uses natural-language-like elements, making code easier to read and understand; it also automates tasks such as memory allocation and management.

  4. What does it mean that Python is interpreted?

    A Python script is executed in the form in which it was written, rather than first being translated into a machine-specific executable in the manner described for compiled languages.

  5. What does it mean that Python is dynamically typed?

    Python infers a variable’s type from the value assigned to it, so the programmer does not need to declare the type in advance.

  6. Why is Python considered relatively easy to learn?

    Its readable, English-like syntax is comparatively easy for beginners to understand and write.

  7. What does it mean that Python is free and open source?

    Its source code is publicly available for people to download, use, modify, and distribute.

  8. How can Python’s concise syntax affect coding time?

    Python often requires fewer lines of code, which can reduce the time needed to write a program; a simple Hello World program can take one line.

  9. What role does Python play in data science and machine learning?

    It is a widely preferred language in these fields, supported by libraries for data analysis and machine learning.

  10. How can Python’s community help a programmer?

    A large community provides people a programmer can ask for help when they get stuck.

  11. What career advantage can learning Python offer?

    Its use across many domains can provide access to a range of career opportunities.

  12. What does object-oriented programming mean in Python?

    Programs can be organized into individual objects, helping make code more structured and easier to understand.

  13. What does it mean that Python is cross-platform?

    A Python program written on one operating system, such as Windows, can generally run on another, such as Linux, with little or no modification.

  14. Which domains and applications of Python are described?

    Web development, data analysis, machine learning, game development, and automation. The content also identifies Python as useful across fields such as data science.

  15. What kinds of tasks can Python automate?

    Repetitive tasks such as sending emails, opening a browser, and posting a social media status.

  16. Which Python libraries or modules are named for particular applications?

    NumPy and pandas for data analysis; scikit-learn and TensorFlow for machine learning; and Pygame for game development.

  17. What is the source material’s main recommendation for a beginner choosing between Python 2 and Python 3?

    Choose Python 3 rather than spending time learning the increasingly obsolete Python 2.

  18. Why does the content recommend Python 3 over Python 2?

    It describes Python 3 as having improving runtime performance and stronger community support, while development was not focused on making Python 2.7 faster.

  19. What example is given of a company migrating from Python 2 to Python 3?

    Instagram migrated the majority of its Python codebase from Python 2.7 to Python 3 in 2017.

  20. What are some ways to write Python code?

    Use the Python command-line interface, a text editor such as Notepad or Notepad++, or a Python IDE.

  21. What is Anaconda, and why does the content recommend it?

    Anaconda is a Python distribution that includes Python, Jupyter Notebook, and other commonly used packages.

  22. What is Jupyter Notebook?

    A web-based application for writing and executing Python code, described as providing an interactive data-science environment.

  23. What is Python indentation important for?

    Python relies heavily on indentation, so coding tools such as IDEs can help with writing and debugging properly indented programs.

  24. What is a Python token?

    A token is a smallest meaningful component of Python source code.

  25. What are the four token categories described in the content?

    Keywords, literals, identifiers, and operators.

  26. What is a Python keyword?

    A reserved word with a specific purpose and meaning in Python; it cannot be used as an identifier.

  27. What is an identifier in Python?

    A name given to a variable, function, or class.

  28. Which characters are allowed in a Python identifier according to the content?

    Letters, digits, and underscores can be used, but no special character other than the underscore is allowed.

  29. What rule applies to the first character of a Python identifier?

    It may be a letter or an underscore, but it cannot be a digit.

  30. Can a Python keyword be used as a variable, class, or function name?

    No. Keywords such as if and while are reserved and cannot be used as identifiers.

  31. Is Python case-sensitive when interpreting identifiers?

    Yes. For example, a and A are different identifiers.

  32. How do you assign one value to a Python variable?

    Write the variable name, an equals sign, and the value, such as a = 10. Python infers the value’s type.

  33. How can one value be assigned to several variables at once?

    Use chained assignment, such as a = b = c = 10.

  34. How can different values be assigned to several variables at once?

    Use matching comma-separated names and values, such as x, y, z = 20, 30, 40.

  35. What is a literal in Python?

    A fixed value written directly in the code, such as data assigned to a variable or constant.

  36. What four kinds of literals are described?

    String, numeric, Boolean, and special literals.

  37. How can a string literal be written in Python?

    Enclose text in either single quotes or double quotes.

  38. How does the content show a multiline string being written?

    Enclose the text in three matching quotes, such as triple single quotes, and put the lines between them.

  39. What determines whether a numeric literal is an integer or a float?

    A numeric literal without a decimal point is an integer; one with a decimal point is a float.

  40. How many decimal points can a numeric literal contain?

    At most one.

  41. What values can Boolean literals have, and how are they used?

    True and False; they represent the outcomes of conditions and are also Python keywords.

  42. What does the special literal None represent?

    The absence of a value; the content compares it to null in languages such as C, C++, and Java.

  43. How can you find the type of a value or variable in Python?

    Use the type() function, for example, type(a).

  44. Does Python require a variable’s type to be declared before assigning a value?

    No. Python infers the type from the assigned value.

  45. Can Python convert a number from one type to another automatically?

    Yes. Python can automatically convert a number between numeric types when appropriate.

  46. Which functions does the content name for explicitly converting numeric types?

    int(), long(), float(), and complex() are named in the content.

  47. Which numeric types are listed in the content?

    Integer, long integer, floating-point, and complex numbers.

  48. Which Python data types are described as immutable?

    Numbers, strings, and tuples.

  49. Which Python data types are described as mutable?

    Lists, dictionaries, and sets.

  50. What is the purpose of an arithmetic operator?

    To perform an arithmetic calculation on operands. Examples include addition, subtraction, multiplication, division, and modulo.

  51. What does an assignment operator do?

    It assigns a value to a variable. The equals sign is a basic assignment operator.

  52. What does the augmented assignment var += 10 mean?

    It is shorthand for var = var + 10.

  53. What does the augmented assignment var -= 10 mean?

    It is shorthand for var = var - 10.

  54. What does the augmented assignment a *= 10 mean?

    It is shorthand for multiplying a by 10 and assigning the result back to a.

  55. What does a comparison operator return?

    A Boolean result, True or False, indicating how two values compare.

  56. Which comparison operators are listed in the content?

    Less than, greater than, less than or equal to, greater than or equal to, and not equal to.

  57. What are Python’s logical operators according to the content?

    and, or, and not.

  58. What is the result of False and True, and why?

    False. With and, both operands must be true for the result to be true.

  59. What do bitwise operators act on?

    The binary representation of values, performing operations on individual bits.

  60. Which bitwise operators are described in the content?

    Bitwise AND, OR, NOT, left shift, and right shift.

  61. What are the results of 7 | 5 and 7 & 5?

    7 | 5 is 7, and 7 & 5 is 5. In binary, 7 is 111 and 5 is 101.

  62. What is the result of bitwise NOT applied to 7 in the example?

    ~7 is -8.

  63. What does a right-shift operator do?

    It shifts a value’s bits to the right by the specified number of positions; for example, 10 >> 2 gives 2.

  64. What does a left-shift operator do?

    It shifts a value’s bits to the left by the specified number of positions; for example, 10 << 2 gives 40.

  65. What do the identity operators is and is not test?

    They test whether two operands share an identity or do not share an identity.

  66. What do the membership operators in and not in test?

    Whether a value is or is not a member of a sequence, such as a list, string, or tuple.

  67. In the example list ['dog', 'cat', 'wolf'], what do the membership tests for 'lion' and 'wolf' return?

    'lion' in the list is False; 'wolf' in the list is True.

  68. What numeric categories does the content identify?

    Integer, long integer, floating-point, and complex numbers.

  69. How does Python handle very large integers, according to the content?

    Integer values can grow according to the available memory rather than being limited to a fixed integer width.

  70. How can you access the first character of a string?

    Use index 0, such as str1[0].

  71. How can you access the last character of a string?

    Use index -1, such as str2[-1].

  72. How can you extract the first five characters of a string?

    Use the slice string[0:5]. The stop index is excluded, so the slice includes indices 0 through 4.

  73. How does Python’s find() string method work?

    It returns the position where the searched-for substring begins. In the example, searching for me in Attachment returns 6.

  74. How does Python’s replace() string method work?

    It returns a string with the specified occurrence of one character or substring replaced by another; for example, replace('ME', 'm') replaces ME with m.

  75. How can replace() remove a substring from a string?

    Replace the substring with an empty string, such as replacing ment with '' to remove it.

Card 1 of 75
Card 1 of 75

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent