But you could use str() function to recast contents as a string like this:
2) Python provides a built-in function, type(), which allows you to determine the type of a variable at any point:
3) Convert the variable to a string: contents = str (contents);
4) Python can change variable types on-the-fly, MEL cannot.
5) There have some keywords you cannot use for variable names, you could find all the keywords by execute: import keyword;
for kw in keyword.kwlist: print(kw);
6) In Python, all data are objects, and each object has:
Identity: describes its address in memory
Type (which is itself an object): describes the data type it references
Value: describes the actual contents of its data
7) When you change the type of the variable, you are not actually altering the data's underlying type, but are point to some different piece of data altogether. You can confirm this fact by using the built-in id() function, which provides the address to the data.
8) Tuples, strings and numbers are all immutable which means cannot have their values changed (mutated).
Two immutable variables with the same assignment (eg. data with the same type and value) may in fact be pointing to the same data in memory.
Two separate assignments to mutable objects with the same type and value are always guaranteed to be different.
9) del(), allows you to delete variables, nit the same as deleting the data referenced by the variable.
10) The none type: var = None;
One use of this type is to initialize a name without wastefully allocating memory if it is unnecessary.
No comments:
Post a Comment