Python.docx - PYTHON All data types are by default string...

  • No School
  • AA 1
  • 3

This preview shows page 1 - 3 out of 3 pages.

PYTHON All data types are by default string. So to calculate age, instead of 2019 – birth_year, correct code will be 2019 – int(birth_year) For inputting values you have to equate a variable to store the input data, Eg. Name = input(‘ what is your name? ‘) To display characters on the basis of their position in the string (indexes) . eg. Course = ‘Python for beginners’ print([ : ]) will print the complete string print([0:2]) will print characters of position 0 and 1 i.e Py print([0:-2]) will print entire string except the last two characters i.e Python for beginner For concatenating strings Eg. first = ‘john’ last = ‘smith’ msg = f’{john} [{smith}] is a coder ‘ print(msg) output : john smith is a coder Different string functions Course = ‘python’ 1. For length : Print(len(course)) Output: 6 2. For upper and lower :
Image of page 1

Subscribe to view the full document.

Image of page 2
Image of page 3

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes