Wikipedia:Reference desk/Archives/Computing/2021 February 18
Appearance
Computing desk | ||
---|---|---|
< February 17 | << Jan | February | Mar >> | February 19 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
February 18
[edit]Tuples being immutable
[edit]With this code:
oldies = (122,125,116,114,119) oldies = oldies[2:] print(oldies)
I get "(116,114,119)" for my output, but I thought that tuples are supposed to be immutable? Or would this count as a replacement of a tuple rather than as an edit of a tuple, thus making it allowed whereas edits of tuples are NOT allowed? Futurist110 (talk) 04:17, 18 February 2021 (UTC)
- You're replacing the reference to the tuple, not the tuple itself. You can't edit the tuple itself but you can replace it outright because you're not using the same tuple. Python has no typing, only optional type hints, so variable references can be modified to anything. WhoAteMyButter (📨│📝) 04:56, 18 February 2021 (UTC)
- To elaborate on the likely source of confusion:
foo = some_value
is always a valid Python assignment, which replaces (rebinds?) the name foo to the value.foo = some_sequence[index]
is somewhat similar, assumingsome_sequence[index]
is valid.foo[index] = some_value
superficially looks similar but is in fact very different; it tries to change the value referenced by foo without rebinding. TigraanClick here to contact me 09:22, 18 February 2021 (UTC) - As "proof" of how this works, you can display
id(oldies)
before and after the second assignment, and you'll see that it changes, meaning thatoldies
has become a different object. In contrast, ifoldies
was an array and you made the assignmentoldies[1]=999
then the id would remain the same. AndrewWTaylor (talk) 11:41, 18 February 2021 (UTC)
- To elaborate on the likely source of confusion:
Windows 10 not showing battery percentage for Bluetooth headphones.
[edit]From recent days, Windows 10 not showing battery percentage for Bluetooth headphones. How to fix this? Rizosome (talk) 12:11, 18 February 2021 (UTC)
- I didn't realize bluetooth headphones report their battery status to the computer. With the old-style BT earpiece and speaker that I use, the computer just doesn't know the device's charge level. Instead, an LED on the device starts blinking when it needs a recharge. I wonder if the BT profiles for those devices even give it a way to report the battery level. Has anyone ever seen anything like that? 2601:648:8200:970:0:0:0:C942 (talk) 22:36, 18 February 2021 (UTC)
- Battery level reporting is optional for bluetooth devices, so it varies from device to device. If the headphones used to show a percentage, and don't anymore, that's a problem with the headphones (broken bluetooth comms?) WhoAteMyButter (📨│📝) 04:52, 19 February 2021 (UTC)
@WhoAteMyButter: so there is no fix? Rizosome (talk) 05:46, 19 February 2021 (UTC)
- @Rizosome: Try with another pair of headphones that supports battery reporting. If it still doesn't work, it's an issue with Windows 10. WhoAteMyButter (📨│📝) 05:50, 19 February 2021 (UTC)