GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Python Basics

Star Boss Englisch 17 Karten

Karten in diesem Stapel (17)

  1. 1difference between built-in function repr() and str()Now if you go by the official python documentation – the __str__ is used to find the “informal”(readable) string representation of an object whereas __repr__ is used to find the “official” string representation of an object.
    The difference between the formal and informal representations is that the default implementation of __repr__ for a str value can be called as an argument to eval, and the return value would be a valid string object. This function (repr()) takes a string and evaluates it’s content as python code.
    >>> import datetime
    >>> now = datetime.datetime.now()
    >>> str(now)
    '2019-03-29 01:29:23.211924'
    >>> repr(now)
    'datetime.datetime(2019, 3, 29, 1, 29, 23, 211924)'
    In above output, the str(now) computes a string containing the value of now whereas repr(now) again returns the python code needed to rebuild our now object.
  2. 2Python function to convert string to lower case and upper caseupper()
    lower()
  3. 3List comprehensionList comprehensions are a third way of making lists. With this elegant approach, you could rewrite the for loop from the first example in just a single line of code:[expression for item in list]
    e.g. squares = [i * i for i in range(10)]
  4. 4Python way to find if object is of specific typeisinstance(object, type)
  5. 5Python way to find type of variabletype()
  6. 6what is lambda functionA lambda function is a small anonymous function.
    A lambda function can take any number of arguments, but can only have one expression.
    lambda arguments : expression
    x = lambda a, b : a * b
  7. 7Python listsList is a collection which is ordered and changeable. Allows duplicate members.
    thislist = ["apple", "banana", "cherry"]
  8. 8Python TupleTuple is a collection which is ordered and unchangeable. Allows duplicate members.
  9. 9Python SetSet is a collection which is unordered and unindexed. No duplicate members.
  10. 10Python DictDictionary is a collection which is unordered, changeable and indexed. No duplicate members.
  11. 11thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[-4:-1]) What will be printed?["orange", "kiwi", "melon", "mango"]
  12. 12What does [::-1]reverses the list
    The slice statement means start at string length, end at position 0, move with the step -1 (or one step backward)
  13. 13Ways of reversing the list and difference between themslicing operator: [::-1] - creates new array
    reverse() - reverses original array, in-place
    reversed(arr) - creating a reverse iterator to create a reverse order of our list in Python. This means that a new list isn’t created, and our old list is not modified. Instead, the function will cycle through all of the elements in our list and return them in reverse order.
  14. 14What is iteratorAn iterator is an object that contains a countable number of values.
    An iterator is an object that can be iterated upon, meaning that you can traverse through all the values.
    Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__().
    https://www.w3schools.com/python/python_iterators.asp
  15. 15Function to fill zereos to stringstr.zfill(,) where len is total length of output string
  16. 16what is enumerate() used for?Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object. This enumerate object can then be used directly in for loops or be converted into a list of tuples using list() method.
  17. 17enumerate() used for?Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object. This enumerate object can then be used directly in for loops or be converted into a list of tuples using list() method.

Informationen

Beschreibung
Karteikarten am Python Basics, erstellt von Star Boss am 17/09/2020.
Erstellt von
Star Boss
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck