Question about String index?

Dear all,

julia> s = "abcdefg"
"abcdefg"

julia> s[end-4, end]
ERROR: MethodError: no method matching axes(::String, ::Int64)
Closest candidates are:
  axes(::AbstractDataFrame, ::Integer) at ~/.julia/packages/DataFrames/zqFGs/src/abstractdataframe/abstractdataframe.jl:366
  axes(::Number, ::Integer) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/number.jl:83
  axes(::Base.Broadcast.Broadcasted{<:Any, <:Tuple{Vararg{T, N}} where T}, ::Integer) where N at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/broadcast.jl:227
  ...
Stacktrace:
 [1] lastindex(a::String, d::Int64)
   @ Base ./abstractarray.jl:373
 [2] top-level scope
   @ REPL[91]:1

Why can not use s[end-4, end]?

Because a , separates dimensions in indexing while ranges are noted with a :

You want s[end-4:end]

Thanks. I have another question.

julia> x = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> x[end-1, end]
2

Here why does not gives error, but gives result of 2?

In julia, a scalar has its index.

julia> C = 1
1

julia> C[1]
1

julia> C[begin]
1

julia> C[end]
1