Python code question. (Basic question)

Asked 2 years ago, Updated 2 years ago, 21 views

num1 = 'It is a clear act of treason that the offensive forces in front of the enemy are moving freely without orders from above. "What about the people who left us behind and left you?"'
num2 = 'However, Woo Wang and Choi Young ignored another possibility that Lee Seong-gye, who was driven to a dead end, could choose.'
The fault of Lee Seong-gye, who carried out the Wihwado Revolutions with the theory of num3 = '4 impossibility, could be made up by this.'

Text like this

print(num1.split())

# It is an act of rebellion, such as "enemy land", "in front of the eyes", "attack forces", "upper", "without orders", "as you wish", "as you wish", "as you wish", "as you wish", "as you wish", "as you wish", "as you wish", "as you wish".', "We", "Leave Us", "Only You", "Go", "Remain", "Being", "People", "What should we do", "It was"]  

In addition to num1, I would like to do split() for other texts.

for i in range(1, 4):  
    num = 'num{}'.format(i)  
    print(num.split())    

But if you do this,

['num1']
['num2']
['num3']

This is what happens. How do we solve this?

python

2022-09-21 15:22

1 Answers

If I were you, I'd like to boldly turn around and change the data structure and strategy

nums = [
    It is a clear act of treason that the offensive forces, which are in front of the enemy's territory, return at will without orders from their superiors. "What about the people who left us behind and left you?"',
    However, Woo Wang and Choi Young ignored another possibility for Lee Sung-gye, who was driven to a dead end.',
    The fault of Lee Seong-gye, who carried out the Wihwa-do rally with the theory of "four impossibilities," could be made up by this.'
]

# The key is to use the list instead of inserting each target string into a separate variable, such as num1 and num2.
# In most languages, especially Python, getting or specifying variable names is not a very good idea.

# To find a third string in this list:
print(nums[2])

# To add a separate string:
Nums.append ("Choi Young fell as Lee Sung-gye came to the forefront of history."")

# To work on this entire list:
for num in nums :
    print(num.split())

# It's easy, right?


2022-09-21 15:22

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.