Cara mencetak kata dari string dengan python

Terkadang kami menemukan situasi di mana kami perlu mendapatkan kata pertama dalam string python. Oleh karena itu sering membantu untuk memiliki steno untuk melakukan fungsi ini. Artikel ini juga membahas situasi di mana kita membutuhkan semua kata yang ada dalam string

Daftar isi

Metode #1. Menggunakan split()

Dengan menggunakan fungsi pemisahan, kita dapat memecah string menjadi daftar kata-kata. Gunakan str. split() dan daftar pengindeksan untuk mendapatkan kata pertama dalam sebuah string. Hubungi str. split() untuk membuat daftar semua kata dalam str yang dipisahkan oleh spasi atau karakter baris baru. Indeks hasil str. split() dengan [0] untuk mengembalikan kata pertama di str

Dapatkan kata pertama dalam string Python

Mendapatkan kata pertama dalam sebuah string akan mengembalikan rangkaian karakter pertama yang mendahului spasi atau karakter baris baru. Misalnya, mendapatkan kata pertama dalam string “Situs Web Tutorial” mengembalikan “Tutorial. ”

2

3

4

5

6

7

 

string = "Situs Web Tutorial"

semua kata = string. pisah()

kata_pertama= semua_kata[0]

cetak(kata_pertama)

 

Keluaran

2

3

4

 

Tutorial

 

Dapatkan Semua kata dalam sebuah string

Mendapatkan semua kata dalam sebuah string akan mengembalikan rangkaian karakter yang mendahului spasi atau karakter baris baru. Misalnya,

2

3

4

5

6

 

string = "Situs Web Tutorial adalah Portal Tutorial Pengembangan Web Online Terbaik"

semua kata = string. pisah()

cetak(semua_kata)

 

Keluaran

2

3

4

 

['Tutorial', 'Situs web', 'is', 'the', 'best', 'Online', 'Web', 'Development', 'Tutorials', 'Portal']

 

Baca Juga. Python vs Node.js. JS. Mana yang paling cocok untuk proyek Anda?

Kesimpulan

Menggunakan fungsi Split untuk Mendapatkan kata pertama dalam string python adalah metode yang paling umum dan direkomendasikan untuk melakukan tugas khusus ini. Tapi kekurangannya adalah gagal mengandung tanda baca dalam kasus string

Pekerjakan Desainer dan Pengembang Situs Web Terbaik Di Delhi India

Pradeep Maurya

Pradeep Maurya adalah Pengembang & Desainer Web Profesional dan Pendiri "situs web Tutorial". Dia tinggal di Delhi dan suka menjadi orang yang mandiri. Sebagai pemilik, dia mencoba yang terbaik untuk meningkatkan platform ini dari hari ke hari. Gairah, dedikasi, dan kemampuan pengambilan keputusan yang cepat untuk berdiri terpisah dari orang lain. Dia seorang blogger yang rajin dan menulis di publikasi seperti Dzone, e27. bersama

Tulis program Python yang mencetak teks panjang, mengubahnya menjadi daftar, dan mencetak semua kata dan frekuensi setiap kata

Contoh Solusi

Kode Piton

string_words = '''United States Declaration of Independence From Wikipedia, the free encyclopedia The United States Declaration of Independence is the statement adopted by the Second Continental Congress meeting at the Pennsylvania State House (Independence Hall) in Philadelphia on July 4, 1776, which announced that the thirteen American colonies, then at war with the Kingdom of Great Britain, regarded themselves as thirteen independent sovereign states, no longer under British rule. These states would found a new nation – the United States of America. John Adams was a leader in pushing for independence, which was passed on July 2 with no opposing vote cast. A committee of five had already drafted the formal declaration, to be ready when Congress voted on independence. John Adams persuaded the committee to select Thomas Jefferson to compose the original draft of the document, which Congress would edit to produce the final version. The Declaration was ultimately a formal explanation of why Congress had voted on July 2 to declare independence from Great Britain, more than a year after the outbreak of the American Revolutionary War. The next day, Adams wrote to his wife Abigail: "The Second Day of July 1776, will be the most memorable Epocha, in the History of America." But Independence Day is actually celebrated on July 4, the date that the Declaration of Independence was approved. After ratifying the text on July 4, Congress issued the Declaration of Independence in several forms. It was initially published as the printed Dunlap broadside that was widely distributed and read to the public. The source copy used for this printing has been lost, and may have been a copy in Thomas Jefferson's hand.[5] Jefferson's original draft, complete with changes made by John Adams and Benjamin Franklin, and Jefferson's notes of changes made by Congress, are preserved at the Library of Congress. The best-known version of the Declaration is a signed copy that is displayed at the National Archives in Washington, D.C., and which is popularly regarded as the official document. This engrossed copy was ordered by Congress on July 19 and signed primarily on August 2. The sources and interpretation of the Declaration have been the subject of much scholarly inquiry. The Declaration justified the independence of the United States by listing colonial grievances against King George III, and by asserting certain natural and legal rights, including a right of revolution. Having served its original purpose in announcing independence, references to the text of the Declaration were few in the following years. Abraham Lincoln made it the centerpiece of his rhetoric (as in the Gettysburg Address of 1863) and his policies. Since then, it has become a well-known statement on human rights, particularly its second sentence: We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. This has been called "one of the best-known sentences in the English language", containing "the most potent and consequential words in American history". The passage came to represent a moral standard to which the United States should strive. This view was notably promoted by Abraham Lincoln, who considered the Declaration to be the foundation of his political philosophy and argued that it is a statement of principles through which the United States Constitution should be interpreted. The U.S. Declaration of Independence inspired many other similar documents in other countries, the first being the 1789 Declaration of Flanders issued during the Brabant Revolution in the Austrian Netherlands (modern-day Belgium). It also served as the primary model for numerous declarations of independence across Europe and Latin America, as well as Africa (Liberia) and Oceania (New Zealand) during the first half of the 19th century.''' word_list = string_words.split() word_freq = [word_list.count(n) for n in word_list] print("String:\n {} \n".format(string_words)) print("List:\n {} \n".format(str(word_list))) print("Pairs (Words and Frequencies:\n {}".format(str(list(zip(word_list, word_freq)))))

Keluaran Sampel

String: United States Declaration of Independence From Wikipedia, the free encyclopedia The United States Declaration of Independence is the statement adopted by the Second Continental Congress meeting at the Pennsylvania State House (Independence Hall) in Philadelphia on July 4, 1776, which announced that the thirteen American colonies, then at war with the Kingdom of Great Britain, regarded themselves as thirteen independent sovereign states, no longer under British rule. These states would found a new nation – the United States of America. John Adams was a leader in pushing for independence, which was passed on July 2 with no opposing vote cast. A committee of five had already drafted the formal declaration, to be ready when Congress voted on independence. John Adams persuaded the committee to select Thomas Jefferson to compose the original draft of the document, which Congress would edit to produce the final version. The Declaration was ultimately a formal explanation of why Congress had voted on July 2 to declare independence from Great Britain, more than a year after the outbreak of the American Revolutionary War. The next day, Adams wrote to his wife Abigail: "The Second Day of July 1776, will be the most memorable Epocha, in the History of America." But Independence Day is actually celebrated on July 4, the date that the Declaration of Independence was approved. After ratifying the text on July 4, Congress issued the Declaration of Independence in several forms. It was initially published as the printed Dunlap broadside that was widely distributed and read to the public. The source copy used for this printing has been lost, and may have been a copy in Thomas Jefferson's hand.[5] Jefferson's original draft, complete with changes made by John Adams and Benjamin Franklin, and Jefferson's notes of changes made by Congress, are preserved at the Library of Congress. The best-known version of the Declaration is a signed copy that is displayed at the National Archives in Washington, D.C., and which is popularly regarded as the official document. This engrossed copy was ordered by Congress on July 19 and signed primarily on August 2. The sources and interpretation of the Declaration have been the subject of much scholarly inquiry. The Declaration justified the independence of the United States by listing colonial grievances against King George III, and by asserting certain natural and legal rights, including a right of revolution. Having served its original purpose in announcing independence, references to the text of the Declaration were few in the following years. Abraham Lincoln made it the centerpiece of his rhetoric (as in the Gettysburg Address of 1863) and his policies. Since then, it has become a well-known statement on human rights, particularly its second sentence: We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. This has been called "one of the best-known sentences in the English language", containing "the most potent and consequential words in American history". The passage came to represent a moral standard to which the United States should strive. This view was notably promoted by Abraham Lincoln, who considered the Declaration to be the foundation of his political philosophy and argued that it is a statement of principles through which the United States Constitution should be interpreted. The U.S. Declaration of Independence inspired many other similar documents in other countries, the first being the 1789 Declaration of Flanders issued during the Brabant Revolution in the Austrian Netherlands (modern-day Belgium). It also served as the primary model for numerous declarations of independence across Europe and Latin America, as well as Africa (Liberia) and Oceania (New Zealand) during the first half of the 19th century. List: ['United', 'States', 'Declaration', 'of', 'Independence', 'From', 'Wikipedia,', 'the', 'free', 'encyclopedia', 'The', 'United', 'States', 'Declaration', 'of', 'Independence', 'is', 'the', 'statement', 'adopted', 'by', 'the', 'Second', 'Continental', 'Congress', 'meeting', 'at', 'the', 'Pennsylvania', 'State', 'House', '(Independence', 'Hall)', 'in', 'Philadelphia', 'on', 'July', '4,', '1776,', 'which', 'announced', 'that', 'the', 'thirteen', 'American', 'colonies,', 'then', 'at', 'war', 'with', 'the', 'Kingdom', 'of', 'Great', 'Britain,', 'regarded', 'themselves', 'as', 'thirteen', 'independent', 'sovereign', 'states,', 'no', 'longer', 'under', 'British', 'rule.', 'These', 'states', 'would', 'found', 'a', 'new', 'nation', '–', 'the', 'United', 'States', 'of', 'America.', 'John', 'Adams', 'was', 'a', 'leader', 'in', 'pushing', 'for', 'independence,', 'which', 'was', 'passed', 'on', 'July', '2', 'with', 'no', 'opposing', 'vote', 'cast.', 'A', 'committee', 'of', 'five', 'had', 'already', 'drafted', 'the', 'formal', 'declaration,', 'to', 'be', 'ready', 'when', 'Congress', 'voted', 'on', 'independence.', 'John', 'Adams', 'persuaded', 'the', 'committee', 'to', 'select', 'Thomas', 'Jefferson', 'to', 'compose', 'the', 'original', 'draft', 'of', 'the', 'document,', 'which', 'Congress', 'would', 'edit', 'to', 'produce', 'the', 'final', 'version.', 'The', 'Declaration', 'was', 'ultimately', 'a', 'formal', 'explanation', 'of', 'why', 'Congress', 'had', 'voted', 'on', 'July', '2', 'to', 'declare', 'independence', 'from', 'Great', 'Britain,', 'more', 'than', 'a', 'year', 'after', 'the', 'outbreak', 'of', 'the', 'American', 'Revolutionary', 'War.', 'The', 'next', 'day,', 'Adams', 'wrote', 'to', 'his', 'wife', 'Abigail:', '"The', 'Second', 'Day', 'of', 'July', '1776,', 'will', 'be', 'the', 'most', 'memorable', 'Epocha,', 'in', 'the', 'History', 'of', 'America."', 'But', 'Independence', 'Day', 'is', 'actually', 'celebrated', 'on', 'July', '4,', 'the', 'date', 'that', 'the', 'Declaration', 'of', 'Independence', 'was', 'approved.', 'After', 'ratifying', 'the', 'text', 'on', 'July', '4,', 'Congress', 'issued', 'the', 'Declaration', 'of', 'Independence', 'in', 'several', 'forms.', 'It', 'was', 'initially', 'published', 'as', 'the', 'printed', 'Dunlap', 'broadside', 'that', 'was', 'widely', 'distributed', 'and', 'read', 'to', 'the', 'public.', 'The', 'source', 'copy', 'used', 'for', 'this', 'printing', 'has', 'been', 'lost,', 'and', 'may', 'have', 'been', 'a', 'copy', 'in', 'Thomas', "Jefferson's", 'hand.[5]', "Jefferson's", 'original', 'draft,', 'complete', 'with', 'changes', 'made', 'by', 'John', 'Adams', 'and', 'Benjamin', 'Franklin,', 'and', "Jefferson's", 'notes', 'of', 'changes', 'made', 'by', 'Congress,', 'are', 'preserved', 'at', 'the', 'Library', 'of', 'Congress.', 'The', 'best-known', 'version', 'of', 'the', 'Declaration', 'is', 'a', 'signed', 'copy', 'that', 'is', 'displayed', 'at', 'the', 'National', 'Archives', 'in', 'Washington,', 'D.C.,', 'and', 'which', 'is', 'popularly', 'regarded', 'as', 'the', 'official', 'document.', 'This', 'engrossed', 'copy', 'was', 'ordered', 'by', 'Congress', 'on', 'July', '19', 'and', 'signed', 'primarily', 'on', 'August', '2.', 'The', 'sources', 'and', 'interpretation', 'of', 'the', 'Declaration', 'have', 'been', 'the', 'subject', 'of', 'much', 'scholarly', 'inquiry.', 'The', 'Declaration', 'justified', 'the', 'independence', 'of', 'the', 'United', 'States', 'by', 'listing', 'colonial', 'grievances', 'against', 'King', 'George', 'III,', 'and', 'by', 'asserting', 'certain', 'natural', 'and', 'legal', 'rights,', 'including', 'a', 'right', 'of', 'revolution.', 'Having', 'served', 'its', 'original', 'purpose', 'in', 'announcing', 'independence,', 'references', 'to', 'the', 'text', 'of', 'the', 'Declaration', 'were', 'few', 'in', 'the', 'following', 'years.', 'Abraham', 'Lincoln', 'made', 'it', 'the', 'centerpiece', 'of', 'his', 'rhetoric', '(as', 'in', 'the', 'Gettysburg', 'Address', 'of', '1863)', 'and', 'his', 'policies.', 'Since', 'then,', 'it', 'has', 'become', 'a', 'well-known', 'statement', 'on', 'human', 'rights,', 'particularly', 'its', 'second', 'sentence:', 'We', 'hold', 'these', 'truths', 'to', 'be', 'self-evident,', 'that', 'all', 'men', 'are', 'created', 'equal,', 'that', 'they', 'are', 'endowed', 'by', 'their', 'Creator', 'with', 'certain', 'unalienable', 'Rights,', 'that', 'among', 'these', 'are', 'Life,', 'Liberty', 'and', 'the', 'pursuit', 'of', 'Happiness.', 'This', 'has', 'been', 'called', '"one', 'of', 'the', 'best-known', 'sentences', 'in', 'the', 'English', 'language",', 'containing', '"the', 'most', 'potent', 'and', 'consequential', 'words', 'in', 'American', 'history".', 'The', 'passage', 'came', 'to', 'represent', 'a', 'moral', 'standard', 'to', 'which', 'the', 'United', 'States', 'should', 'strive.', 'This', 'view', 'was', 'notably', 'promoted', 'by', 'Abraham', 'Lincoln,', 'who', 'considered', 'the', 'Declaration', 'to', 'be', 'the', 'foundation', 'of', 'his', 'political', 'philosophy', 'and', 'argued', 'that', 'it', 'is', 'a', 'statement', 'of', 'principles', 'through', 'which', 'the', 'United', 'States', 'Constitution', 'should', 'be', 'interpreted.', 'The', 'U.S.', 'Declaration', 'of', 'Independence', 'inspired', 'many', 'other', 'similar', 'documents', 'in', 'other', 'countries,', 'the', 'first', 'being', 'the', '1789', 'Declaration', 'of', 'Flanders', 'issued', 'during', 'the', 'Brabant', 'Revolution', 'in', 'the', 'Austrian', 'Netherlands', '(modern-day', 'Belgium).', 'It', 'also', 'served', 'as', 'the', 'primary', 'model', 'for', 'numerous', 'declarations', 'of', 'independence', 'across', 'Europe', 'and', 'Latin', 'America,', 'as', 'well', 'as', 'Africa', '(Liberia)', 'and', 'Oceania', '(New', 'Zealand)', 'during', 'the', 'first', 'half', 'of', 'the', '19th', 'century.'] Pairs (Words and Frequencies: [('United', 6), ('States', 6), ('Declaration', 12), ('of', 30), ('Independence', 6), ('From', 1), ('Wikipedia,', 1), ('the', 49), ('free', 1), ('encyclopedia', 1), ('The', 9), ('United', 6), ('States', 6), ('Declaration', 12), ('of', 30), ('Independence', 6), ('is', 6), ('the', 49), ('statement', 3), ('adopted', 1), ('by', 8), ('the', 49), ('Second', 2), ('Continental', 1), ('Congress', 6), ('meeting', 1), ('at', 4), ('the', 49), ('Pennsylvania', 1), ('State', 1), ('House', 1), ('(Independence', 1), ('Hall)', 1), ('in', 13), ('Philadelphia', 1), ('on', 9), ('July', 7), ('4,', 3), ('1776,', 2), ('which', 6), ('announced', 1), ('that', 8), ('the', 49), ('thirteen', 2), ('American', 3), ('colonies,', 1), ('then', 1), ('at', 4), ('war', 1), ('with', 4), ('the', 49), ('Kingdom', 1), ('of', 30), ('Great', 2), ('Britain,', 2), ('regarded', 2), ('themselves', 1), ('as', 6), ('thirteen', 2), ('independent', 1), ('sovereign', 1), ('states,', 1), ('no', 2), ('longer', 1), ('under', 1), ('British', 1), ('rule.', 1), ('These', 1), ('states', 1), ('would', 2), ('found', 1), ('a', 10), ('new', 1), ('nation', 1), ('–', 1), ('the', 49), ('United', 6), ('States', 6), ('of', 30), ('America.', 1), ('John', 3), ('Adams', 4), ('was', 8), ('a', 10), ('leader', 1), ('in', 13), ('pushing', 1), ('for', 3), ('independence,', 2), ('which', 6), ('was', 8), ('passed', 1), ('on', 9), ('July', 7), ('2', 2), ('with', 4), ('no', 2), ('opposing', 1), ('vote', 1), ('cast.', 1), ('A', 1), ('committee', 2), ('of', 30), ('five', 1), ('had', 2), ('already', 1), ('drafted', 1), ('the', 49), ('formal', 2), ('declaration,', 1), ('to', 12), ('be', 5), ('ready', 1), ('when', 1), ('Congress', 6), ('voted', 2), ('on', 9), ('independence.', 1), ('John', 3), ('Adams', 4), ('persuaded', 1), ('the', 49), ('committee', 2), ('to', 12), ('select', 1), ('Thomas', 2), ('Jefferson', 1), ('to', 12), ('compose', 1), ('the', 49), ('original', 3), ('draft', 1), ('of', 30), ('the', 49), ('document,', 1), ('which', 6), ('Congress', 6), ('would', 2), ('edit', 1), ('to', 12), ('produce', 1), ('the', 49), ('final', 1), ('version.', 1), ('The', 9), ('Declaration', 12), ('was', 8), ('ultimately', 1), ('a', 10), ('formal', 2), ('explanation', 1), ('of', 30), ('why', 1), ('Congress', 6), ('had', 2), ('voted', 2), ('on', 9), ('July', 7), ('2', 2), ('to', 12), ('declare', 1), ('independence', 3), ('from', 1), ('Great', 2), ('Britain,', 2), ('more', 1), ('than', 1), ('a', 10), ('year', 1), ('after', 1), ('the', 49), ('outbreak', 1), ('of', 30), ('the', 49), ('American', 3), ('Revolutionary', 1), ('War.', 1), ('The', 9), ('next', 1), ('day,', 1), ('Adams', 4), ('wrote', 1), ('to', 12), ('his', 4), ('wife', 1), ('Abigail:', 1), ('"The', 1), ('Second', 2), ('Day', 2), ('of', 30), ('July', 7), ('1776,', 2), ('will', 1), ('be', 5), ('the', 49), ('most', 2), ('memorable', 1), ('Epocha,', 1), ('in', 13), ('the', 49), ('History', 1), ('of', 30), ('America."', 1), ('But', 1), ('Independence', 6), ('Day', 2), ('is', 6), ('actually', 1), ('celebrated', 1), ('on', 9), ('July', 7), ('4,', 3), ('the', 49), ('date', 1), ('that', 8), ('the', 49), ('Declaration', 12), ('of', 30), ('Independence', 6), ('was', 8), ('approved.', 1), ('After', 1), ('ratifying', 1), ('the', 49), ('text', 2), ('on', 9), ('July', 7), ('4,', 3), ('Congress', 6), ('issued', 2), ('the', 49), ('Declaration', 12), ('of', 30), ('Independence', 6), ('in', 13), ('several', 1), ('forms.', 1), ('It', 2), ('was', 8), ('initially', 1), ('published', 1), ('as', 6), ('the', 49), ('printed', 1), ('Dunlap', 1), ('broadside', 1), ('that', 8), ('was', 8), ('widely', 1), ('distributed', 1), ('and', 15), ('read', 1), ('to', 12), ('the', 49), ('public.', 1), ('The', 9), ('source', 1), ('copy', 4), ('used', 1), ('for', 3), ('this', 1), ('printing', 1), ('has', 3), ('been', 4), ('lost,', 1), ('and', 15), ('may', 1), ('have', 2), ('been', 4), ('a', 10), ('copy', 4), ('in', 13), ('Thomas', 2), ("Jefferson's", 3), ('hand.[5]', 1), ("Jefferson's", 3), ('original', 3), ('draft,', 1), ('complete', 1), ('with', 4), ('changes', 2), ('made', 3), ('by', 8), ('John', 3), ('Adams', 4), ('and', 15), ('Benjamin', 1), ('Franklin,', 1), ('and', 15), ("Jefferson's", 3), ('notes', 1), ('of', 30), ('changes', 2), ('made', 3), ('by', 8), ('Congress,', 1), ('are', 4), ('preserved', 1), ('at', 4), ('the', 49), ('Library', 1), ('of', 30), ('Congress.', 1), ('The', 9), ('best-known', 2), ('version', 1), ('of', 30), ('the', 49), ('Declaration', 12), ('is', 6), ('a', 10), ('signed', 2), ('copy', 4), ('that', 8), ('is', 6), ('displayed', 1), ('at', 4), ('the', 49), ('National', 1), ('Archives', 1), ('in', 13), ('Washington,', 1), ('D.C.,', 1), ('and', 15), ('which', 6), ('is', 6), ('popularly', 1), ('regarded', 2), ('as', 6), ('the', 49), ('official', 1), ('document.', 1), ('This', 3), ('engrossed', 1), ('copy', 4), ('was', 8), ('ordered', 1), ('by', 8), ('Congress', 6), ('on', 9), ('July', 7), ('19', 1), ('and', 15), ('signed', 2), ('primarily', 1), ('on', 9), ('August', 1), ('2.', 1), ('The', 9), ('sources', 1), ('and', 15), ('interpretation', 1), ('of', 30), ('the', 49), ('Declaration', 12), ('have', 2), ('been', 4), ('the', 49), ('subject', 1), ('of', 30), ('much', 1), ('scholarly', 1), ('inquiry.', 1), ('The', 9), ('Declaration', 12), ('justified', 1), ('the', 49), ('independence', 3), ('of', 30), ('the', 49), ('United', 6), ('States', 6), ('by', 8), ('listing', 1), ('colonial', 1), ('grievances', 1), ('against', 1), ('King', 1), ('George', 1), ('III,', 1), ('and', 15), ('by', 8), ('asserting', 1), ('certain', 2), ('natural', 1), ('and', 15), ('legal', 1), ('rights,', 2), ('including', 1), ('a', 10), ('right', 1), ('of', 30), ('revolution.', 1), ('Having', 1), ('served', 2), ('its', 2), ('original', 3), ('purpose', 1), ('in', 13), ('announcing', 1), ('independence,', 2), ('references', 1), ('to', 12), ('the', 49), ('text', 2), ('of', 30), ('the', 49), ('Declaration', 12), ('were', 1), ('few', 1), ('in', 13), ('the', 49), ('following', 1), ('years.', 1), ('Abraham', 2), ('Lincoln', 1), ('made', 3), ('it', 3), ('the', 49), ('centerpiece', 1), ('of', 30), ('his', 4), ('rhetoric', 1), ('(as', 1), ('in', 13), ('the', 49), ('Gettysburg', 1), ('Address', 1), ('of', 30), ('1863)', 1), ('and', 15), ('his', 4), ('policies.', 1), ('Since', 1), ('then,', 1), ('it', 3), ('has', 3), ('become', 1), ('a', 10), ('well-known', 1), ('statement', 3), ('on', 9), ('human', 1), ('rights,', 2), ('particularly', 1), ('its', 2), ('second', 1), ('sentence:', 1), ('We', 1), ('hold', 1), ('these', 2), ('truths', 1), ('to', 12), ('be', 5), ('self-evident,', 1), ('that', 8), ('all', 1), ('men', 1), ('are', 4), ('created', 1), ('equal,', 1), ('that', 8), ('they', 1), ('are', 4), ('endowed', 1), ('by', 8), ('their', 1), ('Creator', 1), ('with', 4), ('certain', 2), ('unalienable', 1), ('Rights,', 1), ('that', 8), ('among', 1), ('these', 2), ('are', 4), ('Life,', 1), ('Liberty', 1), ('and', 15), ('the', 49), ('pursuit', 1), ('of', 30), ('Happiness.', 1), ('This', 3), ('has', 3), ('been', 4), ('called', 1), ('"one', 1), ('of', 30), ('the', 49), ('best-known', 2), ('sentences', 1), ('in', 13), ('the', 49), ('English', 1), ('language",', 1), ('containing', 1), ('"the', 1), ('most', 2), ('potent', 1), ('and', 15), ('consequential', 1), ('words', 1), ('in', 13), ('American', 3), ('history".', 1), ('The', 9), ('passage', 1), ('came', 1), ('to', 12), ('represent', 1), ('a', 10), ('moral', 1), ('standard', 1), ('to', 12), ('which', 6), ('the', 49), ('United', 6), ('States', 6), ('should', 2), ('strive.', 1), ('This', 3), ('view', 1), ('was', 8), ('notably', 1), ('promoted', 1), ('by', 8), ('Abraham', 2), ('Lincoln,', 1), ('who', 1), ('considered', 1), ('the', 49), ('Declaration', 12), ('to', 12), ('be', 5), ('the', 49), ('foundation', 1), ('of', 30), ('his', 4), ('political', 1), ('philosophy', 1), ('and', 15), ('argued', 1), ('that', 8), ('it', 3), ('is', 6), ('a', 10), ('statement', 3), ('of', 30), ('principles', 1), ('through', 1), ('which', 6), ('the', 49), ('United', 6), ('States', 6), ('Constitution', 1), ('should', 2), ('be', 5), ('interpreted.', 1), ('The', 9), ('U.S.', 1), ('Declaration', 12), ('of', 30), ('Independence', 6), ('inspired', 1), ('many', 1), ('other', 2), ('similar', 1), ('documents', 1), ('in', 13), ('other', 2), ('countries,', 1), ('the', 49), ('first', 2), ('being', 1), ('the', 49), ('1789', 1), ('Declaration', 12), ('of', 30), ('Flanders', 1), ('issued', 2), ('during', 2), ('the', 49), ('Brabant', 1), ('Revolution', 1), ('in', 13), ('the', 49), ('Austrian', 1), ('Netherlands', 1), ('(modern-day', 1), ('Belgium).', 1), ('It', 2), ('also', 1), ('served', 2), ('as', 6), ('the', 49), ('primary', 1), ('model', 1), ('for', 3), ('numerous', 1), ('declarations', 1), ('of', 30), ('independence', 3), ('across', 1), ('Europe', 1), ('and', 15), ('Latin', 1), ('America,', 1), ('as', 6), ('well', 1), ('as', 6), ('Africa', 1), ('(Liberia)', 1), ('and', 15), ('Oceania', 1), ('(New', 1), ('Zealand)', 1), ('during', 2), ('the', 49), ('first', 2), ('half', 1), ('of', 30), ('the', 49), ('19th', 1), ('century.', 1)] _

Presentasi Bergambar


Flow chart


Visualisasikan eksekusi kode Python

Alat berikut memvisualisasikan apa yang dilakukan komputer langkah demi langkah saat menjalankan program tersebut

Editor Kode Python

 

Punya cara lain untuk menyelesaikan solusi ini?

Sebelumnya. Tulis program Python untuk membuat kombinasi kombo 3 digit
Berikutnya. Tulis program Python untuk menghitung jumlah setiap karakter dari file teks

Berapa tingkat kesulitan latihan ini?

Mudah Sedang Keras

Uji keterampilan Pemrograman Anda dengan kuis w3resource



Ikuti kami di Facebook dan Twitter untuk pembaruan terbaru.

Piton. Kiat Hari Ini

string F

Merupakan praktik umum untuk menambahkan variabel di dalam string. Senar F sejauh ini merupakan cara paling keren untuk melakukannya. Untuk lebih menghargai string f, pertama-tama mari kita lakukan operasi dengan fungsi format

name = 'Owen' age = 25 print("{} is {} years old".format(name, age))

Keluaran

Owen is 25 years old

Kami menentukan variabel yang masuk ke dalam kurung kurawal dengan menggunakan fungsi format di bagian akhir. String F memungkinkan untuk menentukan variabel di dalam string

Bagaimana cara mengekstrak teks dari string dengan Python?

Anda dapat mengekstrak substring dalam rentang mulai . Jika awal dihilangkan, rentangnya dari awal, dan jika akhir dihilangkan, rentangnya sampai akhir. Anda juga dapat menggunakan nilai negatif. Jika start > end , tidak ada error yang muncul dan karakter kosong '' diekstrak.

Bagaimana cara mencetak huruf tertentu dari sebuah string dengan Python?

yang perlu Anda lakukan adalah tambahkan tanda kurung dengan nomor karakter di akhir nama string yang ingin Anda cetak , i. e.

Bagaimana cara mengekstrak kata dari string?

Jika kita ingin mengekstrak kata tertentu dari string dan kita tidak mengetahui posisi pasti kata tersebut, kita dapat mencari posisi kata menggunakan find() terlebih dahulu . .

Postingan terbaru

LIHAT SEMUA