This question already has answers here:
python - name of np array variable as string
(2 answers)
Closed 9 months ago.
If I wish to get the name of a numpy.ndarray converted to a string (but not the content of the numpy.ndarray, just the name only), how do I do that?
I tried str(npndarrayName) and npndarrayName.tostring() but both are converting the content and not the name itself only.
I am not sure if I fully understood what you're asking, but you can check this link because I think they had the same question as you.
I hope that it will solve your problem.
Related
This question already has answers here:
Understanding negative steps in list slicing
(2 answers)
Closed 1 year ago.
I am learning python and I can't solve this problem:
I am ok to reverse the whole string but I want to get only the "Hello" part
astring = "Hello world!"
I was expecting print(astring[0:4:-1]) would do the work but it does not.
print(astring[5:0:-1]) is better but the H is still missing. I get "olle"
Is there anyway to solve this?
Thank you,
Try this:
print(astring[4::-1])
This question already has answers here:
How can I read inputs as numbers?
(10 answers)
Closed 2 years ago.
enter image description here
I wrote a simple code in python.
Originally my assignment is to receive two inputs(name of person) and print them.
Here's my question.
When I try to sum two variables but one of them is int and another one is str, an error occurs.
But in this case (the picture) why variable 'a' is recognized as a str not int?
I think there must occurs an error but a is recognized as a str and work well.
In Python 3, input() always returns a string. (In Python 2, input() would try to interpret – well, evaluate, actually – things, which was not a good idea in hindsight. That's why it was changed.)
If you want to (try to) make it an int, you'll need int(input(...)).
This question already has answers here:
How to set a variable name with space in python [closed]
(2 answers)
Valid characters in a python class name
(4 answers)
Closed 2 years ago.
Can a space be given in variable naming. I tried a python program but it's showing an error I have attached the screenshot of the same.
enter image description here
You can't give a space. It's violating the naming convention. What you can do, add underscore (_) between words. Here is the correction:
Gal_Gadot = "Gal Gadot"
print(Gal_Gadot);
Hope this makes sense.
This question already has answers here:
What does the 'b' character do in front of a string literal?
(11 answers)
Convert a bytes array into JSON format
(8 answers)
Closed 2 years ago.
new to python here. Been trying this for quite a while now; would really appreciate some help.
I thought to try my hand at pulling data from an api, and what i got is a very long dictionary ( or at least i think its an dictionary )
response = requests.get('https://api.coingecko.com/api/v3/finance_products')
print(response.content)
can anyone give me any pointers on how to manipulate the results ?
I can't call the dictionary.
First few characters of it :
b'[{"platform":"Binance Savings","identifier":"CCOCOS30DAYSS001","supply_rate_percentage":"6.0","borrow_rate_percentage":null,"number_duration":null,"length_duration":null,"start_at":0,"end_at":0,"value_at":0,"redeem_at":0},{"platform":"DDEX Lending","identifier": etc etc
i'm not sure why there is a b' at the front.
Sorry if this isn't a clear question.
You can use
response.json()
which decodes it immediatly to a json object. Documentation here
This question already has answers here:
Type Error: Format Requires Mapping
(2 answers)
Closed 3 years ago.
text1="Python"
text2="with me"
print("Study %(language)s" %{'language':text1})
This works. But I am wondering whether it is using dictionary to call string?
print("Study %(language)s %(with whom)" %({'language':text1},{'with whom':text2}))
But it doesn't work. How can I fix it?
The error says 'format requires a mapping'
It would have worked, if you noticed that:
you've forgotten to put an s after %(with whom) --> %(with whom)s,
and instead of this %({'language':text1},{'with whom':text2}) --> %{'language':text1,'with whom':text2}
so the line would be like this:
print("Study %(language)s %(with whom)s" %{'language':text1,'with whom':text2})