1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ehidna [41]
2 years ago
12

Assume the variable myWord references a string. Write a statement that uses a slicing

Computers and Technology
1 answer:
givi [52]2 years ago
3 0

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

You might be interested in
You are late in the preparation of the computer graphics for your final report and presentation. You run into a friend who is gr
icang [17]

Answer:

Tactic Exchange

Explanation:

The approaching style of the student to his/her friend for help is of an influence categorized as the "Exchange Influence Tactic".

The Exchange Influence Tactic refers to when a person persuades someone or seeks influence over him/her by offering some sort of reward for their help rendered. It might also work by reminding other person of any favor which you offered in the past that should be repaid now.

Here the student is seeking help of his/her friend for completion of a final report for which he/she is already late. In exchange the student is assuring his/her friend the completion of certain spreadsheets which are pending on him/her. Hence, the student has used the exchange tactic to get his work done by offering a favor in response.

3 0
4 years ago
One limitation of high-level programming languages is
faltersainse [42]

Answer:

One limitation of high-level programming languages is It takes additional translation times to translate the source to machine code

<em>High level programs are comparatively slower than low level programs. Compared to low level programs, they are generally less memory efficient. Cannot communicate directly with the hardware.</em>

4 0
3 years ago
3 Points
Setler [38]

Answer:

olpt software

Explanation:

4 0
3 years ago
Read 2 more answers
Why is it important to think about the programming language to use?
gogolik [260]

Answer:

"The choice of programming language determines the type of game you can make."

Explanation:

Programming language enables us to write efficient programs and develop online things based on the certain type of code.

5 0
3 years ago
Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
stira [4]
I believe it is B hope this helped you<span />
5 0
3 years ago
Other questions:
  • WILL UPVOTE ALL.
    7·1 answer
  • If you come to a stumbling block and can't think of any more ideas, what could you do? select all that apply 2pts.
    11·2 answers
  • Which of these planets has the coldest surface temperature?
    6·2 answers
  • A technician is talking to end users about the specifications for an upgraded application server. The users of the application r
    11·1 answer
  • "the magical number seven, plus or minus two" refers to the storage capacity of ________ memory.
    5·2 answers
  • A technician is configuring a new SOHO multifunction wireless router at a customer’s location to provide network access to sever
    12·1 answer
  • Which type of microscope can only be used to view non-living specimens?
    10·2 answers
  • 27. If X and Y are int type variables,
    14·1 answer
  • State the function of the <br> BIOS,​
    11·1 answer
  • Type the correct answer in each box. Spell all words correctly, and use numerals instead of words for numbers. If necessary, use
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!