Actions

Python for beginners/some vocabulary: Difference between revisions

From Algolit

(Python for Beginners some vocabulary)
Line 1: Line 1:
 
+
Other pages: [[Python_for_beginners|Python for Beginners]] // [[Python_for_beginners/loops_and_conditions|Loops and Conditions]] // [[Python_for_beginners/anthology|Create anthology]]
  
 
* A string or string object is a MODULE in Python  
 
* A string or string object is a MODULE in Python  

Revision as of 15:34, 21 November 2015

Other pages: Python for Beginners // Loops and Conditions // Create anthology

  • A string or string object is a MODULE in Python
  • A MODULE is a file, which contains Python statements.

Normally among these there are:

    • definition statements - the execution of the module defines some functions
    • class statements - the execution of the module defines some classes.

A module may also contain names (variables) and other directly executable Python statements.

    • you can write your own definitions/functions and save them I a file that you can import into another python-file
    • such a document is an external module, called at the beginning of a script using 'import name_module'


  • CLASSES contain METHODS, a series of FUNCTIONS that are part of a class

The string-module contains classes with functions that allow you to calculate the length of the sting, slice etc

  • Anything in Python can be an OBJECT, because it can be assigned to a variable or can be an argument (input) for a function - see also OBJECT ORIENTED PROGRAMMING
  • An ATTRIBUTE is is a way to move from one object to the other

“Apply the power of the almighty dot” - objectname.attributename – and magic!

Note: to know the attributes of an object: dir()

This means the object has a method called __dir__()

dir() calls this method and prints the list of attributes

>>> sentence = "This is so exciting!"

>>> dir(sentence)

>>> suffix = "ing!"

>>> print(sentence.endswith(suffix))

>>> len(sentence)

>>> print(sentence.endswith(suffix,20))

>>> print(sentence.endswith(suffix,16))

>>> print(sentence.endswith(suffix,16,20))


    • Exercise: think of formula that gives TRUE for suffix 'is'

Note: a long string can be annotated using 3 """ a lot of words """

If you have a very long string, you better use:

very_long_string = (

   "For a long time I used to go to bed early." 
 
   "There was no one in the house. Etc etc …."
  )