How To Input a List in Python - Besant Technologies

文章推薦指數: 80 %
投票人數:10人

How to Input a list in python? ... The list is one of the data structure in python. It is basically a collection of certain items. These items are separated by ... OurBestOfferEver!!SummerSpecial-Get3Coursesat24,999/-Only.Readmore ContactUs Chennai:+91-8099770770 Bangalore:+91-8767260270 Online:+91-9707250260 USA:+1-201-949-7520 HireTalent(HR):+91-9791444054 General HomeBlogsGeneralHowtoInputaListinPython? HowtoInputaListinPython? Introduction Ifyouareusingpython,thensometimesyouneedtotakealistasaninput.Inthisarticle,wehavealookonhowtoinputalistinpython. Apartfromthis,wewillalsohavealookat: Howtoacceptanumberlistasaninput? Howtoacceptastringlistfromtheuser? So,now,let’sgetintoit. HowtoInputalistinpython? Thelistisoneofthedatastructureinpython.Itisbasicallyacollectionofcertainitems. Theseitemsareseparatedbythecomma(,)andthelistisenclosedwiththesquarebrackets(). Inpython,toaccepttheinputsfromtheuser,youcanuseinput()function.Usingthisfunction,youcanacceptastring,integerorevenasinglecharacter.However,eachtypeofinputrequiresadifferentapproach. Let’shavealookateachtypeofinput. LearnPythonfromtheBasictoAdvancedLevelwithHands-onTraining,Placements,andmorewith PythonTraininginBangalore Howtoacceptanumberlistasaninput? Inpython,weusercangiveanumberlistasaninput. Example: input_string=input("Enterthenumberlist:") usList=input_string.split() print("Sumofthelist",usList) sum=0 fornuminuserList: sum+=int(num) print("Sum=",sum) Output: Enterthenumberlist:2469 Sumofthelist Sum=21 Now,letusunderstandhowthisprogramworks: Byusingtheinput()function,itconvertstheinputtoastringandseparatesitwiththespaces. Youcanalsoacceptthestringusingthe(,). Next,youcanusethespilt()functionforpassingtheargument. Afterthis,usingtheinput_string.split()youcanseparatetheinputstringwithspace.Also,convertthemintoanindividualelementandaddittoalist. Lastly,the‘for’loopisforconvertingeveryelementintoanintegerforcalculatingitssum. Nextis,letushavealookatacceptingthestringlistasaninput. GetPlacementOrientedPythonTrainingfromIndustryExpertswithourPythonTraininginChennai Howtoacceptastringlistasaninput? Apartfromthenumberlist,wecanalsoacceptthestringasaninputfromtheuser.Inpython,itispossibletogetastringasaninput. Example: input_st=input(“schoolsnames“) school=input_st.split(",") print("Schoolnames") fornameinschool: print(name) Output: writethenameofyourschoolsNkvv,Besant,stella Schoolnames Nkvv Besant Stella Letmeexplaintheprogramfirst: Theinputlistelementsofastringcanbeseparatedbyacomma. Withtheinput_st.split(“,”)wecansplitastringwiththecommaandcreatealistofstring. Iteratealistwithaforloopandprinttheschoolname. LearnPythonCoursetoBoostyourCarrerwithourPythonOnlineTraining RelatedBlogs: BriefOverviewofPythonLanguage PythonCareeropportunities PythonBreakContinue PythonControlFlow PythonDataTypes PythonDictionary PythonExceptionHandling  PythonFile PythonFunctions PythonSubstring Next Searchfor: TopCategories Blogs(507) General(388) InterviewQuestions(90) JobOpeninginBangalore(9) JobOpeninginChennai(15) RecentPost SoftwareTestingSyllabus SalesforceCourseSyllabus DataAnalyticsCourseSyllabus ITSalaryinIndia InfosysSystemEngineerSalary2022inIndia TrendingCoursesMasterProgram WatchPlacedStudentsReview Morevideos RelatedBlogs: SoftwareTestingSyllabus General TheSoftwareTestingsyllabusfromBesantTechnologiescoversallofthetopicsthat... SalesforceCourseSyllabus General SalesforceCourseSyllabuscreatedbyBesantTechnologiesexpertsprovidesindividualswithanoverview... DataAnalyticsCourseSyllabus General OurindustryexpertsframetheDataAnalystCourseSyllabus.Itismeantto... ITSalaryinIndia General ITSalaryInIndia2022-BesantTechnologiesInIndia,anITEngineer's... DropaQuery CallUs WAIT.!!Thisenquirymightchangeyourcareer × Name* 10DigitMobileNo* Email* SelectCourse SelectCourseinterestedinAbInitioAdvanced.NETAdvancedJavaAmazonWebServices(AWS)AndroidAngularJSBigDataAnalyticsC&C++CatiaCCNACloudComputingCognosCognosTM1DatastageDB2DBA.NETETLTestingHadoopHTML4.01&5+CSS3HyperionFinanceManagementHyperionPlanningInformaticaInformaticaDataQualityInformaticaMDMiOSJavaJavaScriptJMeterjQueryLinuxLoadRunnerMainframeAdminMainframeDeveloperManualTestingMicrosoftDynamicsAXTechnicalMicrosoftDynamicsAXFunctionalMicrostrategyMobileApplicationTestingMSBIMVC(.NET)NotinthislistOAFOBIEEOpenStackOracleSQL&PL/SQLOracleDBAOracleAppsDBAOracleAppsFinanceOracleAppsHRMSOracleAppsSCMOracleAppsTechnicalOracleDataIntegrator(ODI)OracleForms&ReportsOracleIdentityManagerOracleRAC,Dataguard,ASMOracleEssbaseOSBPegaPentahoPerformanceTuningPeoplesoftFinancePeoplesoftHCMPerlPHPPMPPrimaveraPro-EPythonOracleADFQlikViewQTPQualityCenter(QC)RProgrammingSalesforceSalesforceDeveloperSalesforceAdminSAPSAPABAPSAPBASISSAPBISAPBOSAPBODSSAPCRMSAPFICOSAPHANASAPHRSAPMMSAPPISAPPPSAPQMSAPSCMSAPSDSAPSuccessFactorsSAPWMSASSCCMSeleniumSEOSharePointAdminSharePointDeveloperSOASoapUISoftwareTestingMSSQLServerDeveloperMSSQLServerDBASybaseDBASybaseDeveloperTableauTeradataDBATeradataDeveloperTestCompleteToolUnixShellScriptingVMwareWCF&WPFWebDesigningWebLogicServerWebSphereApplicationServer(WAS)WebSphereMessageBrokerWebSphereMQWindowsAdmin(MCSA/MCITP)MicrosoftAzureWorkdayInformixMongoDBPostgreSQLTibcoSpotfireAdminApacheSparkWebFOCUSJaspersoftDrupalJoomlaNode.JsAdobeCQ5Backbone.jsExtJSKnockoutJSRequireJSSAPIS-RetailSAPPMSAPPSSAPSRMSAPWebDynProSAPEHSSAPGRCSAPSecurityCoreJavaJ2EESpringStrutsHibernateObjectiveCRubyCucumberWindowsPowerShellAdminOracleRetailTradeManagementOracleDemantraTaleoOracleOTMIBMTivoliwebMethodsSolarisAJAXCCNPScrumMasterRubyonRailsDigitalMarketingApacheAntDotNetNukeNetworkingEmbeddedSystemsChefITAutomationMicrosoftDynamicsCRMMachineLearningusingRBigDataTestingVBACodedUICitrixUnigraphicsNxMicrosoftExcelDevopsMobileDeviceManagementWordPressSuggestACourseANSYSJBossOracleRightNowCRMRevitSPSSWebServicesPHPFrameworksAWSSysOpsAWSTestingHadoopAdminHadoopArchitectVisualBasicDesignPatternGDAndTJDEdwardsMySQLDBAMySQLMSOfficeStorageAreaNetwork(SAN)MainframeIMSGraphicDesigningHybridAppDevelopmentSoftwareDefinedNetwork(SDN)ApacheTomcatDelphiProgrammingIBMSterlingAutoCADManagingSuccessfulProgrammes(MSP)DataScienceOracleGoldenGateWebSpherePortalMicrosoftDynamicsNAVTechnicalMicrosoftDynamicsNAVFunctionalApacheCassandraApacheStormDataScienceWithSasDataScienceWithPythonDataScienceWithRApacheKafkaGit&GitHubJenkinsAnsiblePuppetQlikSenseExcelAndAdvancedExcelForAnalyticsSolidworksMongoDBAdminDockerPhoneGapBusinessObjectsBaseSASHBaseApacheHiveApachePigSeleniumWebDriverSeleniumWithPythonSeleniumWithC#RanorexTestAutomationWebservicesWithSoapuiTestingMicrosoftDynamicsMCSESSISSSRSSSASOpenNebulaRubySqoopMapReduceGoogleAnalyticsPearsonVueExamEthicalHackingGoogleCloudAngular2ReactJSTalendIoTBluePrismAutomationAnywhereUipathOpenspanRPABigDataMastersProgramDataScienceMastersProgramCloudMastersProgramDevopsMastersProgramSoftwareTestingMastersProgramBusinessIntelligenceMastersProgramFreshersMastersProgramBlockchainMEANStackAIAdvancedOracleDBARoboticsTallyWindowsServerAdministrationHTMLCSSRACXamarinFrenchLanguageSpanishLanguageIELTSFullStackwithJavaWebAPIGoogleGoProgrammingLanguageAutomationTestingAngular4Angular5DjangoAppiumPowerBiDataStructures&AlgorithmsSpokenEnglishGermanMachineLearningWithPythonFullStackwithPythonSplunkCyberSecurityPytestMatlabFlutterAndDartProtractorAppianPysparkRaspberryPiCyberarkJapaneseLanguageBpmJbpmMicrosoftBiztalkServerAWSDevOpsAzureDevOpsComputerCoursesinHindiEnglishCourseInHindiTallyCourseInHindiSpringBootEthicalHackingCourseInHindiSeleniumWithCucumberExcelCourseInHindiPhotoshopCourseInHindiCCNACourseInHindiAndroidDevelopmentCourseInHindiPHPTraininginHindiAzureIoTAzureBlockchainAWSMachineLearningAWSIoTAzureMachineLearningAWSBlockchainAngular7Angular8PythonCourseinHindiCyberSecurityCourseinHindiOracleSOASeleniumWithJavaBusinessAnalystReactNativeVue.jsOracleFusionFinancialsPowerpointWebAPIUsingPythonApacheSparkWithPythonMicrosoftDynamics365IBMODMELKStackSAPAutomationUsingRPAPostgreSQLAdminRESTAPISwiftTypeScriptProCScalaAgileVFXandAnimationITILControl-MPyTorchLISPPrologMSProjectJiraSnowflakeCherryPyPhotoshopGSuiteNagiosGradleMicrosoftForefrontBigQueryAmazonRedshiftLaravelTalendAdminDataStructuresAndAlgorithmsCodeigniterRapidminerOracleFusionHCMMicroservicesMulesoftComputingForKidsProgrammingForKidsCSharpDataminingCSharp.netAsp.netOracle(Sql)MernStackExpress.jsAzureDp300KubernetesDeepLearningCProgrammingPhotoshop&IllustatorAppiumJobSupportNetworkTestingAwsDeveloperERPOracle(pl/sql)M365AdministratorExpert(ExamMs100&Ms101)SqlCorePythonSalesforceMarketingCloudAwsCloudPractitionerPowerBiJobSupportJava8Junit5PenetrationTestingAwsSecurityPowerShellDataAnalyticsSalesforceFunctionalConsultantFrontEndwithAngularSeleniumRobotFrameworkMicrosoftIntuneTerraformSalesforceLwc(lightningWebComponents)JavascriptWithAngularJavascriptWithReactjsFrontEndWithReactjsMongoDbWithNodeJsGoogleDataEngineerDataStudioAzureDataFactoryOpenshiftAemTestingFrontendDeveloperMavenAzureFundamentalsSeleniumWithJavascriptUi/uxPlsqlFullstackWithNodejsFlaskPython SelectBranch How&Where??Yes,amInterestedinOnlineTrainingVelacheryTambaramOkkiyamThoraipakkam-OMRPorurAnnaNagarT.NagarThiruvanmiyurMaraimalaiNagarSiruseriMarathahalliBTMLayout2ndStageRajajiNagarJayanagarKalyanNagarElectronicCityIndiraNagarKoramangalaWhitefieldHSRLayoutHebbalRRNagarJ.P.NagarYes,WeareInterestedinCorporateTraining Message*



請為這篇文章評分?