Question

air = 'yes' # I'm feeling hungry so I decide to make a change. air[0] =...

air = 'yes'

# I'm feeling hungry so I decide to make a change.

air[0] = 'P'

# This fails because air is a string and strings are __________________.

Answer is for Python coding. Find blank above.

Homework Answers

Answer #1

Question:
air = 'yes'
# I'm feeling hungry so I decide to make a change.
air[0] = 'P'
# This fails because air is a string and strings are immutable

  • This is because whenever you try to change the characters in the string. You will get an error indicating - TypeError: 'str' object does not support item assignment   
  • In Python, strings are considered to be immutable. Once you create a string, There is no possibility to change the order of the characters or replacing the characters.
  • However, you can able to append new characters or a string to your string
  • If you can observe the question, In the first statement we are creating a string and then
  • In the next statement, we are trying to replace the 1st character in the string using the 0th index with the char 'P'
  • Since this is not possible, because of the immutable nature of the strings. we get an error.

(Feel free to drop me a comment, If you need any help)


Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
Hello I have a question about Java. example So when you put “sum 1 2 3”...
Hello I have a question about Java. example So when you put “sum 1 2 3” in console, you do not seperate those. Need a space between sum 1, 2 in the console. What is Sum? sum 1 2 3 6 (answer) sum 123456 21 sum 7 4 2 13 public static void main (String[] args) { System.out.Println(“What is Sum?”); String a=“”; a = scnr.nextLine(); String[] b = a.split(“”); if(b[0].equals(“sum”) { } I don’t know how to make code for...
I'm trying to write a solver that can find a single solution to a cryptarithmetic puzzle....
I'm trying to write a solver that can find a single solution to a cryptarithmetic puzzle. I need help writing the other function from this code. /* ExhaustiveSolve * --------------- * This is the "not-very-smart" version of cryptarithmetic solver. It takes * the puzzle itself (with the 3 strings for the two addends and sum) and a * string of letters as yet unassigned. If no more letters to assign * then we've hit a base-case, if the current letter-to-digit...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
I'm so confused on how to do the z-score...I was absent for this part of class...
I'm so confused on how to do the z-score...I was absent for this part of class and I need help figuring out how to even answer the following questions. EPA fuel economy for automobiles was found to have a mean of 30 mpg and a standard deviation of 7 mpg. Assume that a Normal model can be applied. Use this information to answer the next four questions. 18. What is the standardized value for a car that got 20 mpg?...
(1 point) Is college worth it? Part I Among a simple random sample of 331 American...
(1 point) Is college worth it? Part I Among a simple random sample of 331 American adults who do not have a four-year college degree and are not currently enrolled in school, 48% said they decided not to go to college because they could not afford school. A newspaper article states that only a minority of the Americans who decide not to go to college do so because they cannot afford it and uses the point estimate from this survey...
Hi! Below is the case study and I want to make sure I'm on the right...
Hi! Below is the case study and I want to make sure I'm on the right track. I bolded the questions I'm interested in (1-5). Looking for people who are familiar with the DSM-5/abnormal psychology and able to answer all questions completely. Thank you! Questions: 1. Diagnosis; what is the evidence for it? 2. Treatment; typical treatment used for this diagnosis AND most effective treatment. IF the person is in treatment, what should we target first in terms of symptoms?...
This must be answered not advance methods, focusing on String method. We are working on Ch...
This must be answered not advance methods, focusing on String method. We are working on Ch 9 in Think Java 1st Ed.I need the program to be bare bones and the coding need to be done the long way with no advanced code. in this lab you will have two methods with headings: - public static int countNumberSigns(String tweetText) - public static int countHashtags(String tweetText) 'String tweetText' means the method is expectiong a string value as an input to it....
A grapefruit farmer in central Florida is trying to decide whether to take protective action to...
A grapefruit farmer in central Florida is trying to decide whether to take protective action to limit damage to his crop in the event that the overnight temperature falls to a level well below freezing. He is concerned that if the temperature falls sufficiently low and he fails to make an effort to protect his grapefruit? trees, he runs the risk of losing his entire? crop, which is worth approximately? $75,000. Based on the latest forecast issued by the National...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT