[D66] points68 (addendum 2)
René Oudeweg
roudeweg at gmail.com
Sat May 6 18:27:18 CEST 2023
MMM... het is makkelijker in python? :
ChatGPT:
I'm sorry, I misunderstood your question earlier. It is possible to use
a period as the name of a variable in Python, but it is not recommended
because it can lead to confusion and errors in your code.
However, if you really want to use a period as the name of a variable,
you can do so by enclosing the variable name in quotes or backticks.
Here is an example:
scss
|globals()['.'] = 'This is a period' print('.') # Output: "This is a
period" |
In this example, the |globals()| function returns a dictionary of all
global variables in the current scope. We then set the value of the key
|'.'| to the string |'This is a period'|. Finally, we print the value of
the variable by referencing it using the period enclosed in quotes. Note
that this is not a recommended practice and can make your code difficult
to read and maintain.
globals()['.'] = 'world'
# concatenate two strings with the period variable in between
string1 = 'Hello'
result = string1 + globals()['.'] + '!'
print(result) # output: "Hello.world!"
# split a string into a list using the period variable as the delimiter
string2 = 'This is a sentence. It has multiple periods.'
result = string2.split(globals()['.'])
print(result) # output: ['This is a sentence', ' It has multiple
periods', '']
# replace all occurrences of the period variable with another character
string3 = 'This is a sentence. It has a period.'
result = string3.replace(globals()['.'], '!')
print(result) # output: "This is a sentence! It has a period!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.tuxtown.net/pipermail/d66/attachments/20230506/d17b60f6/attachment.html>
More information about the D66
mailing list