12 JULY 2019

We learned how scope works in python. what is a scope of a variable? answer: “The scope of a variable refers to the places that you can see or access a variable”. If you define a variable inside a function it becomes a local variable (of the function) and cannot be accessed from outside the function. if you define a variable not in a function- it becomes a global variable. if you try to access a global variable for a read-only purpose inside a function it will be possible, however if you try to change it’s value – the python will make a duplication of the global variable for the scope of the function (and will not affect the global variable value in any way.) if you want to change a global variable inside a function you can use the global keyword (usually not recommended). we leaned about a collection type called Set. A set is a very similar to list except that it holds only distinct values (without repetition). for example, if you add the same item twice into a set- you will still have only one occurrence of this item. we learned about file accessing in python. the open command allows us to access the file in the desired mode (read/ write/ append, etc). we need to make sure we close the file connection after the work is done. we can also use the with statement in python- which closes the file automatically

ww2.png

More topics covered:

  • Scope– function inside a function
  • Set methods – i.e. union
  • file open – a, a+, w, w+ …
  • Seek command
  • with inside with
  • return two variable from function
  • print( ‘….’, end = “”)

Links:

Leave a comment