You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, the following is equivalent to the above
395
413
~~~
396
414
mystring_clean = myString.replace(" ","")
397
415
print(mystring_clean.isalpha())
398
416
~~~
399
417
{: .language-python}
400
418
401
-
402
419
~~~
403
420
True
404
-
0
405
-
THE QUICK BROWN FOX
406
-
The quick brown fox
407
-
False
408
-
True
409
421
~~~
410
422
{: .output}
411
423
412
424
If you need to refer to a specific element (character) in a string,
413
425
you can do so by specifying the index of the character in `[]`
414
-
you can also use indexing to select a substring of the string. In Python,
426
+
you can also use indexing to select a substring of the string. In Python,
415
427
indexes begin with `0` (see [Index Operator: Working with the Characters of a String](http://www.interactivepython.org/courselib/static/thinkcspy/Strings/IndexOperatorWorkingwiththeCharactersofaString.html) for a visual).
416
428
417
429
~~~
@@ -513,7 +525,7 @@ False
513
525
> bool_val1 = 'TRUE'
514
526
> print('read as type ',___(bool_val1))
515
527
> print('value when cast to bool',___(bool_val1))
516
-
>
528
+
>
517
529
> bool_val2 = 'FALSE'
518
530
> print('read as type ',___(bool_val2))
519
531
> print('value when cast to bool',___(bool_val2))
@@ -589,37 +601,37 @@ print(type(list4))
589
601
> We can index lists the same way we indexed strings before. Complete the code below and display the value of `last_num_in_list` which is 11 and values of `odd_from_list` which are 5 and 11 to check your work.
590
602
> ~~~
591
603
> num_list = [4,5,6,11]
592
-
>
604
+
>
593
605
> last_num_in_list = num_list[____]
594
606
> print(last_num_in_list)
595
-
>
607
+
>
596
608
> odd_from_list = [num_list[_____], ______]
597
609
> print(odd_from_list)
598
610
> ~~~
599
611
> {: .language-python}
600
612
> > ## Solution
601
613
> > ~~~
602
-
> > # Solution 1: Basic ways of solving this exercise using the core Python language
614
+
> > # Solution 1: Basic ways of solving this exercise using the core Python language
603
615
> > num_list = [4,5,6,11]
604
-
> >
616
+
> >
605
617
> > last_num_in_list = num_list[-1]
606
618
> > print(last_num_in_list)
607
-
> >
619
+
> >
608
620
> > odd_from_list = [num_list[1], num_list[3]]
609
621
> > print(odd_from_list)
610
622
> >
611
623
> >
612
-
> > # Solutions 2 and 3: Usually there are multiple ways of doing the same work. Once we learn about more advanced Python, we would be able to write more varieties codes like the followings to print the odd numbers:
624
+
> > # Solutions 2 and 3: Usually there are multiple ways of doing the same work. Once we learn about more advanced Python, we would be able to write more varieties codes like the followings to print the odd numbers:
613
625
> > import numpy as np
614
626
> > num_list = [4,5,6,11]
615
-
> >
627
+
> >
616
628
> > # Converting `num_list` list to an advanced data structure: `numpy array`
617
629
> > num_list_np_array = np.array(num_list)
618
-
> >
630
+
> >
619
631
> > # Filtering the elements which produces a remainder of `1`, after dividing by `2`
0 commit comments